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 "lyx_gui_misc.h"
26 #include "bufferparams.h"
28 #include "lyxscreen.h"
29 #include "minibuffer.h"
38 static const int LYX_PAPER_MARGIN = 20;
40 extern int mono_video;
41 extern int reverse_video;
42 extern int fast_selection;
43 extern BufferView * current_view;
47 extern int bibitemMaxWidth(LyXFont const &);
49 #define FIX_DOUBLE_SPACE 1
51 int LyXText::SingleWidth(LyXParagraph * par,
52 LyXParagraph::size_type pos) const
54 char c = par->GetChar(pos);
55 return SingleWidth(par, pos, c);
59 int LyXText::SingleWidth(LyXParagraph * par,
60 LyXParagraph::size_type pos, char c) const
62 LyXFont font = GetFont(par, pos);
64 // The most common case is handled first (Asger)
68 } else if (IsHfillChar(c)) {
69 return 3; /* Because of the representation
70 * as vertical lines */
72 } else if (c == LyXParagraph::META_FOOTNOTE ||
73 c == LyXParagraph::META_MARGIN ||
74 c == LyXParagraph::META_FIG ||
75 c == LyXParagraph::META_TAB ||
76 c == LyXParagraph::META_WIDE_FIG ||
77 c == LyXParagraph::META_WIDE_TAB ||
78 c == LyXParagraph::META_ALGORITHM)
82 case LyXParagraph::META_MARGIN:
85 case LyXParagraph::META_FIG:
88 case LyXParagraph::META_TAB:
91 case LyXParagraph::META_ALGORITHM:
94 case LyXParagraph::META_WIDE_FIG:
97 case LyXParagraph::META_WIDE_TAB:
100 case LyXParagraph::META_FOOTNOTE:
106 return font.stringWidth(fs);
109 else if (c == LyXParagraph::META_INSET) {
110 Inset *tmpinset= par->GetInset(pos);
112 return par->GetInset(pos)->Width(font);
116 } else if (IsSeparatorChar(c))
118 else if (IsNewlineChar(c))
120 return font.width(c);
124 // Returns the paragraph position of the last character in the specified row
125 LyXParagraph::size_type LyXText::RowLast(Row const * row) const
128 return row->par->Last() - 1;
129 else if (row->next->par != row->par)
130 return row->par->Last() - 1;
132 return row->next->pos - 1;
136 LyXDirection BufferParams::getDocumentDirection() const
138 return (lyxrc->rtl_support && language == "hebrew")
139 ? LYX_DIR_RIGHT_TO_LEFT : LYX_DIR_LEFT_TO_RIGHT;
142 LyXDirection LyXParagraph::getParDirection() const
144 if (!lyxrc->rtl_support || table)
145 return LYX_DIR_LEFT_TO_RIGHT;
148 return (getFont(0).direction() == LyXFont::RTL_DIR)
149 ? LYX_DIR_RIGHT_TO_LEFT : LYX_DIR_LEFT_TO_RIGHT;
151 return current_view->buffer()->params.getDocumentDirection();
154 LyXDirection LyXFont::getFontDirection() const
156 if (lyxrc->rtl_support
157 && direction() == LyXFont::RTL_DIR
158 && latex() != LyXFont::ON)
159 return LYX_DIR_RIGHT_TO_LEFT;
161 return LYX_DIR_LEFT_TO_RIGHT;
165 LyXParagraph::getLetterDirection(LyXParagraph::size_type pos) const
167 if (!lyxrc->rtl_support)
168 return LYX_DIR_LEFT_TO_RIGHT;
170 LyXDirection direction = getFont(pos).getFontDirection();
171 if (IsLineSeparator(pos) && 0 < pos && pos < Last() - 1
172 && !IsLineSeparator(pos + 1)
173 && !(table && IsNewline(pos + 1))
174 && (getFont(pos - 1).getFontDirection() != direction
175 || getFont(pos + 1).getFontDirection() != direction))
176 return getParDirection();
182 void LyXText::ComputeBidiTables(Row * row) const
185 if (!lyxrc->rtl_support) {
189 LyXParagraph::size_type last = RowLast(row);
190 bidi_start = row->pos;
192 if (bidi_start > last) {
197 if (last + 2 - bidi_start >
198 static_cast<LyXParagraph::size_type>(log2vis_list.size())) {
199 LyXParagraph::size_type new_size =
200 (last + 2 - bidi_start < 500) ?
201 500 : 2 * (last + 2 - bidi_start);
202 log2vis_list.resize(new_size);
203 vis2log_list.resize(new_size);
206 vis2log_list[last + 1 - bidi_start] = -1;
207 log2vis_list[last + 1 - bidi_start] = -1;
209 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
210 if (main_body > 0 && row->pos < main_body - 1 && main_body - 1 <= last
211 && row->par->IsLineSeparator(main_body - 1)) {
212 // This is needed in case there is a direction change in
213 // the label which is continued into the main body
214 if (row->par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) {
215 ComputeBidiTablesFromTo(row, bidi_start,
217 log2vis_list[main_body - 1 - bidi_start] =
219 vis2log_list[main_body - 1 - bidi_start] =
221 if (main_body <= last)
222 ComputeBidiTablesFromTo(row,
225 ComputeBidiTablesFromTo(row, bidi_start,
227 last - main_body + 2);
228 log2vis_list[main_body - 1 - bidi_start] =
229 last - main_body + 1 + bidi_start;
230 vis2log_list[last - main_body + 1 - bidi_start] =
232 if (main_body <= last)
233 ComputeBidiTablesFromTo(row, main_body,
237 ComputeBidiTablesFromTo(row, bidi_start, last, 0);
241 void LyXText::ComputeBidiTablesFromTo(Row * row,
242 LyXParagraph::size_type from,
243 LyXParagraph::size_type to,
244 LyXParagraph::size_type offset) const
246 LyXParagraph::size_type vpos, old_lpos, stack[2];
247 LyXDirection par_direction = row->par->getParDirection();
248 LyXDirection direction = par_direction;
249 LyXParagraph::size_type lpos = from;
253 if (row->par->getLetterDirection(lpos) == direction) {
254 log2vis_list[lpos - bidi_start] = direction;
258 (level == 1 && direction == LYX_DIR_RIGHT_TO_LEFT
259 && row->par->getFont(lpos).direction() ==
261 && row->par->getFont(lpos).latex() ==
263 // The last check is needed when the
265 stack[level++] = lpos;
267 old_lpos = stack[--level];
268 log2vis_list[old_lpos - bidi_start] =
269 log2vis_list[lpos - bidi_start] =
270 (old_lpos - lpos) * direction;
273 direction = static_cast<LyXDirection>(-direction);
278 old_lpos = stack[--level];
279 log2vis_list[old_lpos - bidi_start] =
280 (old_lpos - (to + 1)) * direction;
281 direction = static_cast<LyXDirection>(-direction);
284 vpos = (par_direction == LYX_DIR_LEFT_TO_RIGHT)
287 for (lpos = from; lpos <= to; ++lpos) {
288 vpos += log2vis_list[lpos - bidi_start];
289 vis2log_list[vpos - bidi_start] = lpos;
290 log2vis_list[lpos - bidi_start] = vpos;
295 void LyXText::Draw(Row const * row, LyXParagraph::size_type & vpos,
296 LyXScreen & scr, int offset, float & x)
298 LyXParagraph::size_type pos = vis2log(vpos);
299 char c = row->par->GetChar(pos);
301 if (IsNewlineChar(c)) {
303 // Draw end-of-line marker
305 LyXFont font = GetFont(row->par, pos);
306 int asc = font.maxAscent();
307 int wid = font.width('n');
308 int y = (offset + row->baseline);
310 if (row->par->getLetterDirection(pos) == LYX_DIR_LEFT_TO_RIGHT) {
311 p[0].x = int(x + wid*0.375); p[0].y = int(y - 0.875*asc*0.75);
312 p[1].x = int(x); p[1].y = int(y - 0.500*asc*0.75);
313 p[2].x = int(x + wid*0.375); p[2].y = int(y - 0.125*asc*0.75);
314 scr.drawLines(::getGC(gc_new_line), p, 3);
316 p[0].x = int(x); p[0].y = int(y - 0.500*asc*0.75);
317 p[1].x = int(x + wid); p[1].y = int(y - 0.500*asc*0.75);
318 p[2].x = int(x + wid); p[2].y = int(y - asc*0.75);
319 scr.drawLines(::getGC(gc_new_line), p, 3);
321 p[0].x = int(x + wid*0.625); p[0].y = int(y - 0.875*asc*0.75);
322 p[1].x = int(x + wid); p[1].y = int(y - 0.500*asc*0.75);
323 p[2].x = int(x + wid*0.625); p[2].y = int(y - 0.125*asc*0.75);
324 scr.drawLines(::getGC(gc_new_line), p, 3);
326 p[0].x = int(x + wid); p[0].y = int(y - 0.500*asc*0.75);
327 p[1].x = int(x); p[1].y = int(y - 0.500*asc*0.75);
328 p[2].x = int(x); p[2].y = int(y - asc*0.75);
329 scr.drawLines(::getGC(gc_new_line), p, 3);
335 LyXFont font = GetFont(row->par, pos);
336 LyXFont font2 = font;
338 if (c == LyXParagraph::META_FOOTNOTE
339 || c == LyXParagraph::META_MARGIN
340 || c == LyXParagraph::META_FIG
341 || c == LyXParagraph::META_TAB
342 || c == LyXParagraph::META_WIDE_FIG
343 || c == LyXParagraph::META_WIDE_TAB
344 || c == LyXParagraph::META_ALGORITHM) {
347 case LyXParagraph::META_MARGIN:
349 // Draw a sign at the left margin!
350 scr.drawText(font, "!", 1, offset + row->baseline,
351 (LYX_PAPER_MARGIN - font.width('!'))/2);
353 case LyXParagraph::META_FIG:
356 case LyXParagraph::META_TAB:
359 case LyXParagraph::META_ALGORITHM:
362 case LyXParagraph::META_WIDE_FIG:
365 case LyXParagraph::META_WIDE_TAB:
368 case LyXParagraph::META_FOOTNOTE:
375 // calculate the position of the footnotemark
376 int y = (row->baseline - font2.maxAscent()
379 font.setColor(LyXFont::INSET);
383 // draw it and set new x position
384 x += scr.drawString(font, fs, offset + y, int(x));
386 scr.drawLine(gc_foot, offset + row->baseline,
387 int(tmpx), int(x - tmpx));
391 } else if (c == LyXParagraph::META_INSET) {
392 Inset * tmpinset = row->par->GetInset(pos);
394 tmpinset->Draw(font, scr, offset + row->baseline, x);
399 /* usual characters, no insets */
401 // Collect character that we can draw in one command
403 // This is dirty, but fast. Notice that it will never be too small.
404 // For the record, I'll note that Microsoft Word has a limit
405 // of 768 here. We have none :-) (Asger)
406 // Ok. I am the first to admit that the use of std::string will be
407 // a tiny bit slower than using a POD char array. However, I claim
408 // that this slowdown is so small that it is close to inperceptive.
409 // So IMHO we should go with the easier and clearer implementation.
410 // And even if 1024 is a large number here it might overflow, string
411 // will only overflow if the machine is out of memory...
412 static string textstring;
416 LyXParagraph::size_type last = RowLast(row);
418 while (vpos <= last &&
419 (pos = vis2log(vpos)) >= 0
420 && static_cast<unsigned char>(c = row->par->GetChar(pos)) > ' '
421 && font2 == GetFont(row->par, pos)) {
427 // If monochrome and LaTeX mode, provide reverse background
429 font.latex() == LyXFont::ON) {
430 int a = font.maxAscent();
431 int d = font.maxDescent();
432 scr.fillRectangle(gc_copy, int(tmpx),
433 offset + row->baseline - a,
434 font.textWidth(textstring.c_str(),
435 textstring.length()), a + d);
438 // Draw text and set the new x position
439 x += scr.drawText(font, textstring.c_str(), textstring.length(),
440 offset + row->baseline,
443 // what about underbars?
444 if (font.underbar() == LyXFont::ON && font.latex() != LyXFont::ON) {
445 scr.drawLine(gc_copy, offset + row->baseline + 2,
446 int(tmpx), int(x - tmpx));
449 // If we want ulem.sty support, drawing
450 // routines should go here. (Asger)
451 // Why shouldn't LyXFont::drawText handle it internally?
455 // Returns the left beginning of the text.
456 // This information cannot be taken from the layouts-objekt, because in
457 // LaTeX the beginning of the text fits in some cases (for example sections)
458 // exactly the label-width.
459 int LyXText::LeftMargin(Row const * row) const
461 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
462 row->par->GetLayout());
464 string parindent = layout.parindent;
466 /* table stuff -- begin */
469 /* table stuff -- end */
471 int x = LYX_PAPER_MARGIN;
473 x += textclasslist.TextClass(parameters->textclass)
475 .signedStringWidth(textclasslist
476 .TextClass(parameters->textclass)
479 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
480 LyXFont font(LyXFont::ALL_SANE);
481 font.setSize(LyXFont::SIZE_SMALL);
482 x += font.textWidth("Mwide-figM", 10) + LYX_PAPER_MARGIN/2;
485 // this is the way, LyX handles the LaTeX-Environments.
486 // I have had this idea very late, so it seems to be a
487 // later added hack and this is true
488 if (!row->par->GetDepth()) {
489 if (!row->par->GetLayout()) {
490 // find the previous same level paragraph
491 if (row->par->FirstPhysicalPar()->Previous()) {
492 LyXParagraph * newpar = row->par
493 ->DepthHook(row->par->GetDepth());
495 textclasslist.Style(parameters->textclass,
502 // find the next level paragraph
504 LyXParagraph * newpar = row->par->DepthHook(row->par->GetDepth()-1);
506 // make a corresponding row. Needed to call LeftMargin()
508 // check wether it is a sufficent paragraph
509 if (newpar && newpar->footnoteflag == row->par->footnoteflag
511 .Style(parameters->textclass,
512 newpar->GetLayout()).isEnvironment()) {
514 dummyrow.par = newpar;
515 dummyrow.pos = newpar->Last();
516 x = LeftMargin(&dummyrow);
518 // this is no longer an error, because this function
519 // is used to clear impossible depths after changing
520 // a layout. Since there is always a redo,
521 // LeftMargin() is always called
522 row->par->FirstPhysicalPar()->depth = 0;
525 if (newpar && !row->par->GetLayout()) {
526 if (newpar->FirstPhysicalPar()->noindent)
529 parindent = textclasslist
530 .Style(parameters->textclass,
531 newpar->GetLayout()).parindent;
536 LyXFont labelfont = GetFont(row->par, -2);
537 switch (layout.margintype) {
539 if (!layout.leftmargin.empty()) {
541 .TextClass(parameters->textclass)
543 .signedStringWidth(layout.leftmargin);
545 if (!row->par->GetLabestring().empty()) {
546 x += labelfont.signedStringWidth(layout.labelindent);
547 x += labelfont.stringWidth(row->par->GetLabestring());
548 x += labelfont.stringWidth(layout.labelsep);
552 x += labelfont.signedStringWidth(layout.labelindent);
553 if (row->pos >= BeginningOfMainBody(row->par)) {
554 if (!row->par->GetLabelWidthString().empty()) {
556 .stringWidth(row->par
557 ->GetLabelWidthString());
558 x += labelfont.stringWidth(layout.labelsep);
563 x += textclasslist.TextClass(parameters->textclass)
564 .defaultfont().signedStringWidth(layout.leftmargin) * 4
565 / (row->par->GetDepth() + 4);
567 case MARGIN_FIRST_DYNAMIC:
568 if (layout.labeltype == LABEL_MANUAL) {
569 if (row->pos >= BeginningOfMainBody(row->par)) {
571 .signedStringWidth(layout.leftmargin);
574 .signedStringWidth(layout.labelindent);
577 // Special case to fix problems with
579 || (layout.labeltype == LABEL_STATIC
580 && layout.latextype == LATEX_ENVIRONMENT
581 && ! row->par->IsFirstInSequence())) {
582 x += labelfont.signedStringWidth(layout.leftmargin);
583 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
584 && layout.labeltype != LABEL_BIBLIO
585 && layout.labeltype !=
586 LABEL_CENTERED_TOP_ENVIRONMENT) {
587 x += labelfont.signedStringWidth(layout.labelindent);
588 x += labelfont.stringWidth(layout.labelsep);
589 x += labelfont.stringWidth(row->par->GetLabestring());
593 case MARGIN_RIGHT_ADDRESS_BOX:
595 // ok, a terrible hack. The left margin depends on the widest
596 // row in this paragraph. Do not care about footnotes, they
597 // are *NOT* allowed in the LaTeX realisation of this layout.
599 // find the first row of this paragraph
600 Row const * tmprow = row;
601 while (tmprow->previous && tmprow->previous->par == row->par)
602 tmprow = tmprow->previous;
604 int minfill = tmprow->fill;
605 while (tmprow->next && tmprow->next->par == row->par) {
606 tmprow = tmprow->next;
607 if (tmprow->fill < minfill)
608 minfill = tmprow->fill;
611 x += textclasslist.TextClass(parameters->textclass)
612 .defaultfont().signedStringWidth(layout.leftmargin);
617 if (row->par->pextra_type == LyXParagraph::PEXTRA_INDENT) {
618 if (!row->par->pextra_widthp.empty()) {
620 atoi(row->par->pextra_widthp.c_str()) / 100;
621 } else if (!row->par->pextra_width.empty()) {
622 int xx = VSpace(row->par->pextra_width).inPixels();
625 xx = paperwidth * 80 / 100;
627 } else { // should not happen
628 LyXFont font(LyXFont::ALL_SANE);
629 x += font.stringWidth("XXXXXX");
634 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
635 align = layout.align;
637 align = row->par->FirstPhysicalPar()->align;
639 // set the correct parindent
641 if ((layout.labeltype == LABEL_NO_LABEL
642 || layout.labeltype == LABEL_TOP_ENVIRONMENT
643 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
644 || (layout.labeltype == LABEL_STATIC
645 && layout.latextype == LATEX_ENVIRONMENT
646 && ! row->par->IsFirstInSequence()))
647 && row->par == row->par->FirstPhysicalPar()
648 && align == LYX_ALIGN_BLOCK
649 && !row->par->noindent
650 && (row->par->layout ||
651 parameters->paragraph_separation ==
652 BufferParams::PARSEP_INDENT))
653 x += textclasslist.TextClass(parameters->textclass)
654 .defaultfont().signedStringWidth(parindent);
656 if (layout.labeltype == LABEL_BIBLIO) {
657 // ale970405 Right width for bibitems
658 x += bibitemMaxWidth(textclasslist
659 .TextClass(parameters
669 int LyXText::RightMargin(Row const * row) const
671 LyXLayout const & layout =
672 textclasslist.Style(parameters->textclass,
673 row->par->GetLayout());
675 int x = LYX_PAPER_MARGIN
677 .TextClass(parameters->textclass)
679 .signedStringWidth(textclasslist
680 .TextClass(parameters->textclass)
683 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
684 x += LYX_PAPER_MARGIN / 2;
687 // this is the way, LyX handles the LaTeX-Environments.
688 // I have had this idea very late, so it seems to be a
689 // later added hack and this is true
690 if (row->par->GetDepth()) {
691 // find the next level paragraph
693 LyXParagraph * newpar = row->par;
696 newpar = newpar->FirstPhysicalPar()->Previous();
698 newpar = newpar->FirstPhysicalPar();
699 } while (newpar && newpar->GetDepth() >= row->par->GetDepth()
700 && newpar->footnoteflag == row->par->footnoteflag);
702 // make a corresponding row. Needed to call LeftMargin()
704 // check wether it is a sufficent paragraph
705 if (newpar && newpar->footnoteflag == row->par->footnoteflag
706 && textclasslist.Style(parameters->textclass,
710 dummyrow.par = newpar;
712 x = RightMargin(&dummyrow);
714 // this is no longer an error, because this function
715 // is used to clear impossible depths after changing
716 // a layout. Since there is always a redo,
717 // LeftMargin() is always called
718 row->par->FirstPhysicalPar()->depth = 0;
722 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
723 x += textclasslist.TextClass(parameters->textclass)
725 .signedStringWidth(layout.rightmargin) * 4
726 / (row->par->GetDepth() + 4);
731 int LyXText::LabelEnd (Row const * row) const
733 if (textclasslist.Style(parameters->textclass,
734 row->par->GetLayout()).margintype
738 tmprow.pos = row->par->Last();
739 return LeftMargin(&tmprow); /* just the beginning
742 return 0; /* LabelEnd is only needed, if the
743 layout fills a flushleft
748 /* table stuff -- begin*/
749 int LyXText::NumberOfCell(LyXParagraph * par,
750 LyXParagraph::size_type pos) const
753 LyXParagraph::size_type tmp_pos = 0;
754 while (tmp_pos < pos) {
755 if (par->IsNewline(tmp_pos))
763 int LyXText::WidthOfCell(LyXParagraph * par,
764 LyXParagraph::size_type & pos) const
767 while (pos < par->Last() && !par->IsNewline(pos)) {
768 w += SingleWidth(par, pos);
771 if (par->IsNewline(pos))
777 bool LyXText::HitInTable(Row * row, int x) const
780 float fill_separator, fill_hfill, fill_label_hfill;
781 if (!row->par->table)
783 PrepareToPrint(row, tmpx, fill_separator,
784 fill_hfill, fill_label_hfill, false);
785 return (x > tmpx && x < tmpx + row->par->table->WidthOfTable());
789 bool LyXText::MouseHitInTable(int x, long y) const
791 Row * row = GetRowNearY(y);
792 return HitInTable(row, x);
796 /* table stuff -- end*/
799 // get the next breakpoint in a given paragraph
800 LyXParagraph::size_type
801 LyXText::NextBreakPoint(Row const * row, int width) const
803 LyXParagraph * par = row->par;
804 LyXParagraph::size_type pos = row->pos;
806 /* table stuff -- begin*/
808 while (pos < par->size()
809 && (!par->IsNewline(pos)
810 || !par->table->IsFirstCell(NumberOfCell(par, pos+1)))) {
811 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
812 par->GetInset(pos) && par->GetInset(pos)->display()){
813 par->GetInset(pos)->display(false);
819 /* table stuff -- end*/
821 // position of the last possible breakpoint
822 // -1 isn't a suitable value, but a flag
823 LyXParagraph::size_type last_separator = -1;
824 int left_margin = LabelEnd(row);
825 width -= RightMargin(row);
827 LyXParagraph::size_type main_body = BeginningOfMainBody(par);
828 LyXLayout const & layout =
829 textclasslist.Style(parameters->textclass, par->GetLayout());
830 LyXParagraph::size_type i = pos;
832 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
833 /* special code for right address boxes, only newlines count */
834 while (i < par->Last()) {
835 if (par->IsNewline(i)) {
837 i = par->Last() - 1; // this means break
839 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
840 par->GetInset(i) && par->GetInset(i)->display()){
841 par->GetInset(i)->display(false);
846 // Last position is an invariant
847 LyXParagraph::size_type const last =
849 // this is the usual handling
850 int x = LeftMargin(row);
851 while (x < width && i < last) {
852 char c = par->GetChar(i);
853 if (IsNewlineChar(c)) {
855 x = width; // this means break
856 } else if (c == LyXParagraph::META_INSET &&
857 par->GetInset(i) && par->GetInset(i)->display()){
858 // check wether a Display() inset is
859 // valid here. if not, change it to
861 if (layout.isCommand()
862 || (layout.labeltype == LABEL_MANUAL
863 && i < BeginningOfMainBody(par))){
864 // display istn't allowd
865 par->GetInset(i)->display(false);
866 x += SingleWidth(par, i, c);
868 // inset is display. So break the line here
872 if (IsLineSeparatorChar(par->GetChar(i+1)))
875 last_separator = last; // to avoid extra rows
877 last_separator = i - 1;
878 x = width; // this means break
881 if (IsLineSeparatorChar(c))
883 x += SingleWidth(par, i, c);
886 if (i == main_body) {
887 x += GetFont(par, -2).stringWidth(layout.labelsep);
888 if (par->IsLineSeparator(i - 1))
889 x-= SingleWidth(par, i - 1);
894 // end of paragraph is always a suitable separator
895 if (i == last && x < width)
899 // well, if last_separator is still 0, the line isn't breakable.
900 // don't care and cut simply at the end
901 if (last_separator < 0) {
905 // manual labels cannot be broken in LaTeX, do not care
906 if (main_body && last_separator < main_body)
907 last_separator = main_body - 1;
909 return last_separator;
913 // returns the minimum space a row needs on the screen in pixel
914 int LyXText::Fill(Row const * row, int paper_width) const
917 // get the pure distance
918 LyXParagraph::size_type last = RowLast(row);
919 /* table stuff -- begin */
920 if (row->par->table) {
921 // for tables FILL does calculate the widthes of each cell in
923 LyXParagraph::size_type pos = row->pos;
924 int cell = NumberOfCell(row->par, pos);
927 row->par->table->SetWidthOfCell(cell,
928 WidthOfCell(row->par,
931 } while (pos <= last && !row->par->table->IsFirstCell(cell));
932 // don't forget the very last table cell without characters
933 if (cell == row->par->table->GetNumberOfCells() - 1)
934 row->par->table->SetWidthOfCell(cell,
935 WidthOfCell(row->par,
938 return 0; /* width of table cannot be returned since
939 * we cannot guarantee its correct value at
942 /* table stuff -- end*/
944 int left_margin = LabelEnd(row);
946 // if the row ends with newline, this newline will not be relevant
947 //if (last >= 0 && row->par->IsNewline(last))
950 // if the row ends with a space, this space will not be relevant
951 if (last >= 0 && row->par->IsLineSeparator(last))
954 // special handling of the right address boxes
955 if (textclasslist.Style(parameters->textclass,
956 row->par->GetLayout()).margintype
957 == MARGIN_RIGHT_ADDRESS_BOX) {
958 int tmpfill = row->fill;
959 row->fill = 0; // the minfill in MarginLeft()
965 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
966 row->par->GetLayout());
967 LyXParagraph::size_type main_body =
968 BeginningOfMainBody(row->par);
969 LyXParagraph::size_type i = row->pos;
972 if (main_body > 0 && i == main_body) {
973 w += GetFont(row->par, -2).
974 stringWidth(layout.labelsep);
975 if (row->par->IsLineSeparator(i - 1))
976 w -= SingleWidth(row->par, i - 1);
980 w += SingleWidth(row->par, i);
983 if (main_body > 0 && main_body > last) {
984 w += GetFont(row->par, -2).stringWidth(layout.labelsep);
985 if (last >= 0 && row->par->IsLineSeparator(last))
986 w -= SingleWidth(row->par, last);
991 fill = paper_width - w - RightMargin(row);
996 // returns the minimum space a manual label needs on the screen in pixel
997 int LyXText::LabelFill(Row const * row) const
999 LyXParagraph::size_type last = BeginningOfMainBody(row->par) - 1;
1000 // -1 because a label ends either with a space that is in the label,
1001 // or with the beginning of a footnote that is outside the label.
1003 // I don't understand this code in depth, but sometimes "last" is
1004 // less than 0 and this causes a crash. This fix seems to work
1005 // correctly, but I bet the real error is elsewhere. The bug is
1006 // triggered when you have an open footnote in a paragraph
1007 // environment with a manual label. (Asger)
1008 if (last < 0) last = 0;
1010 if (row->par->IsLineSeparator(last)) /* a sepearator at this end
1017 w += SingleWidth(row->par, i);
1022 if (!row->par->labelwidthstring.empty()) {
1023 fill = GetFont(row->par, -2)
1024 .stringWidth(row->par->labelwidthstring) - w;
1034 // returns the number of separators in the specified row. The separator
1035 // on the very last column doesnt count
1036 int LyXText::NumberOfSeparators(Row const * row) const
1038 int last = RowLast(row);
1040 //int main_body = BeginningOfMainBody(row->par);
1041 //if (p < main_body)
1043 // I think this is equivalent to the above. (Lgb)
1044 int p = max(row->pos, BeginningOfMainBody(row->par));
1046 for (; p < last; ++p) {
1047 if (row->par->IsSeparator(p)) {
1055 // returns the number of hfills in the specified row. The LyX-Hfill is
1056 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1057 // ignored. This is *MUCH* more usefull than not to ignore!
1058 int LyXText::NumberOfHfills(Row const * row) const
1060 int last = RowLast(row);
1061 int first = row->pos;
1062 if (first) { /* hfill *DO* count at the beginning
1064 while(first <= last && row->par->IsHfill(first))
1068 //int main_body = BeginningOfMainBody(row->par);
1069 //if (first < main_body)
1070 // first = main_body;
1071 // I think this is equivalent to the above. (Lgb)
1072 first = max(first, BeginningOfMainBody(row->par));
1074 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1075 if (row->par->IsHfill(p)) {
1083 // like NumberOfHfills, but only those in the manual label!
1084 int LyXText::NumberOfLabelHfills(Row const * row) const
1086 LyXParagraph::size_type last = RowLast(row);
1087 LyXParagraph::size_type first = row->pos;
1088 if (first) { /* hfill *DO* count at the beginning
1090 while(first < last && row->par->IsHfill(first))
1093 //LyXParagraph::size_type main_body =
1094 //BeginningOfMainBody(row->par);
1095 //if (last > main_body)
1097 // I think this is eqvialent to the above. (Lgb)
1098 last = min(last, BeginningOfMainBody(row->par));
1100 for (LyXParagraph::size_type p = first;
1101 p < last; ++p) { // last, because the end is ignored!
1102 if (row->par->IsHfill(p)) {
1110 // returns true, if a expansion is needed.
1111 // Rules are given by LaTeX
1112 bool LyXText::HfillExpansion(Row const * row_ptr,
1113 LyXParagraph::size_type pos) const
1115 // by the way, is it a hfill?
1116 if (!row_ptr->par->IsHfill(pos))
1119 // at the end of a row it does not count
1120 if (pos >= RowLast(row_ptr))
1123 // at the beginning of a row it does not count, if it is not
1124 // the first row of a paragaph
1128 // in some labels it does not count
1129 if (textclasslist.Style(parameters->textclass,
1130 row_ptr->par->GetLayout()).margintype
1132 && pos < BeginningOfMainBody(row_ptr->par))
1135 // if there is anything between the first char of the row and
1136 // the sepcified position that is not a newline and not a hfill,
1137 // the hfill will count, otherwise not
1138 LyXParagraph::size_type i = row_ptr->pos;
1139 while (i < pos && (row_ptr->par->IsNewline(i)
1140 || row_ptr->par->IsHfill(i)))
1147 void LyXText::SetHeightOfRow(Row * row_ptr) const
1149 /* get the maximum ascent and the maximum descent */
1150 int asc, maxasc, desc, maxdesc, pos_end, pos, labeladdon;
1151 float layoutasc = 0;
1152 float layoutdesc = 0;
1157 /* this must not happen before the currentrow for clear reasons.
1158 so the trick is just to set the current row onto this row */
1160 GetRow(row_ptr->par, row_ptr->pos, unused_y);
1162 /* ok , let us initialize the maxasc and maxdesc value.
1163 * This depends in LaTeX of the font of the last character
1164 * in the paragraph. The hack below is necessary because
1165 * of the possibility of open footnotes */
1167 /* Correction: only the fontsize count. The other properties
1168 are taken from the layoutfont. Nicer on the screen :) */
1170 LyXParagraph * par = row_ptr->par->LastPhysicalPar();
1171 LyXParagraph * firstpar = row_ptr->par->FirstPhysicalPar();
1173 LyXLayout const & layout = textclasslist.Style(parameters->textclass, firstpar->GetLayout());
1175 LyXFont font = GetFont(par, par->Last()-1);
1176 LyXFont::FONT_SIZE size = font.size();
1177 font = GetFont(par, -1);
1180 LyXFont labelfont = GetFont(par, -2);
1182 maxasc = int(font.maxAscent() *
1183 layout.spacing.getValue() *
1184 parameters->spacing.getValue());
1185 maxdesc = int(font.maxDescent() *
1186 layout.spacing.getValue() *
1187 parameters->spacing.getValue());
1189 pos_end = RowLast(row_ptr);
1193 // Check if any insets are larger
1194 for (pos = row_ptr->pos; pos <= pos_end; ++pos) {
1195 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_INSET) {
1196 tmpfont = GetFont(row_ptr->par, pos);
1197 tmpinset = row_ptr->par->GetInset(pos);
1199 asc = tmpinset->Ascent(tmpfont);
1200 desc = tmpinset->Descent(tmpfont);
1209 // Check if any custom fonts are larger (Asger)
1210 // This is not completely correct, but we can live with the small,
1211 // cosmetic error for now.
1212 LyXFont::FONT_SIZE maxsize = row_ptr->par->HighestFontInRange(row_ptr->pos,
1214 if (maxsize > font.size()) {
1215 font.setSize(maxsize);
1217 asc = font.maxAscent();
1218 desc = font.maxDescent();
1225 /* table stuff -- begin*/
1226 if (row_ptr->par->table){
1227 // stretch the rows a bit
1231 /* table stuff -- end*/
1233 // This is nicer with box insets:
1237 row_ptr->ascent_of_text = maxasc;
1239 /* is it a top line? */
1240 if (row_ptr->pos == 0
1241 && row_ptr->par == firstpar) {
1243 /* some parksips VERY EASY IMPLEMENTATION */
1244 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
1245 if (layout.isParagraph()
1246 && firstpar->GetDepth() == 0
1247 && firstpar->Previous())
1248 maxasc += parameters->getDefSkip().inPixels();
1249 else if (firstpar->Previous()
1250 && textclasslist.Style(parameters->textclass,
1251 firstpar->Previous()->GetLayout()).isParagraph()
1252 && firstpar->Previous()->GetDepth() == 0)
1253 // is it right to use defskip here too? (AS)
1254 maxasc += parameters->getDefSkip().inPixels();
1257 /* the paper margins */
1258 if (!row_ptr->par->previous)
1259 maxasc += LYX_PAPER_MARGIN;
1261 /* add the vertical spaces, that the user added */
1262 if (firstpar->added_space_top.kind() != VSpace::NONE)
1263 maxasc += int(firstpar->added_space_top.inPixels());
1265 /* do not forget the DTP-lines!
1266 * there height depends on the font of the nearest character */
1267 if (firstpar->line_top)
1268 maxasc += 2 * GetFont(firstpar, 0).ascent('x');
1270 /* and now the pagebreaks */
1271 if (firstpar->pagebreak_top)
1272 maxasc += 3 * DefaultHeight();
1274 /* this is special code for the chapter, since the label of this
1275 * layout is printed in an extra row */
1276 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1277 && parameters->secnumdepth>= 0) {
1278 labeladdon = int(labelfont.maxDescent() *
1279 layout.spacing.getValue() *
1280 parameters->spacing.getValue())
1281 + int(labelfont.maxAscent() *
1282 layout.spacing.getValue() *
1283 parameters->spacing.getValue());
1286 /* special code for the top label */
1287 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1288 || layout.labeltype == LABEL_BIBLIO
1289 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1290 && row_ptr->par->IsFirstInSequence()
1291 && !row_ptr->par->GetLabestring().empty()) {
1293 (labelfont.maxAscent() *
1294 layout.spacing.getValue() *
1295 parameters->spacing.getValue())
1296 +(labelfont.maxDescent() *
1297 layout.spacing.getValue() *
1298 parameters->spacing.getValue())
1299 + layout.topsep * DefaultHeight()
1300 + layout.labelbottomsep * DefaultHeight());
1303 /* and now the layout spaces, for example before and after a section,
1304 * or between the items of a itemize or enumerate environment */
1306 if (!firstpar->pagebreak_top) {
1307 LyXParagraph *prev = row_ptr->par->Previous();
1309 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth());
1310 if (prev && prev->GetLayout() == firstpar->GetLayout()
1311 && prev->GetDepth() == firstpar->GetDepth()
1312 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1314 layoutasc = (layout.itemsep * DefaultHeight());
1316 else if (row_ptr->previous) {
1317 tmptop = layout.topsep;
1319 if (row_ptr->previous->par->GetDepth() >= row_ptr->par->GetDepth())
1320 tmptop-= textclasslist.Style(parameters->textclass, row_ptr->previous->par->GetLayout()).bottomsep;
1323 layoutasc = (tmptop * DefaultHeight());
1325 else if (row_ptr->par->line_top){
1326 tmptop = layout.topsep;
1329 layoutasc = (tmptop * DefaultHeight());
1332 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth()-1);
1334 maxasc += int(textclasslist.Style(parameters->textclass,
1335 prev->GetLayout()).parsep * DefaultHeight());
1338 if (firstpar->Previous()
1339 && firstpar->Previous()->GetDepth() == 0
1340 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1343 else if (firstpar->Previous()){
1344 maxasc += int(layout.parsep * DefaultHeight());
1350 /* is it a bottom line? */
1351 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
1352 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
1354 /* the paper margins */
1356 maxdesc += LYX_PAPER_MARGIN;
1358 /* add the vertical spaces, that the user added */
1359 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1360 maxdesc += int(firstpar->added_space_bottom.inPixels());
1362 /* do not forget the DTP-lines!
1363 * there height depends on the font of the nearest character */
1364 if (firstpar->line_bottom)
1365 maxdesc += 2 * (GetFont(par, par->Last()-1).ascent('x'));
1367 /* and now the pagebreaks */
1368 if (firstpar->pagebreak_bottom)
1369 maxdesc += 3 * DefaultHeight();
1371 /* and now the layout spaces, for example before and after a section,
1372 * or between the items of a itemize or enumerate environment */
1373 if (!firstpar->pagebreak_bottom && row_ptr->par->Next()) {
1374 LyXParagraph *nextpar = row_ptr->par->Next();
1375 LyXParagraph *comparepar = row_ptr->par;
1379 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1380 usual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1381 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1382 if (comparepar->GetLayout()!= nextpar->GetLayout()
1383 || nextpar->GetLabelWidthString() !=
1384 comparepar->GetLabelWidthString())
1385 unusual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1387 if (unusual > usual)
1388 layoutdesc = unusual;
1392 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1394 if (comparepar->GetLayout()!= nextpar->GetLayout()
1395 || nextpar->GetLabelWidthString() !=
1396 comparepar->GetLabelWidthString())
1397 layoutdesc = int(textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1402 /* incalculate the layout spaces */
1403 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1404 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1406 /* table stuff -- begin*/
1407 if (row_ptr->par->table){
1408 maxasc += row_ptr->par->table->
1409 AdditionalHeight(NumberOfCell(row_ptr->par, row_ptr->pos));
1411 /* table stuff -- end*/
1413 /* calculate the new height of the text */
1414 height -= row_ptr->height;
1416 row_ptr->height= maxasc+maxdesc+labeladdon;
1417 row_ptr->baseline= maxasc+labeladdon;
1419 height += row_ptr->height;
1423 /* Appends the implicit specified paragraph behind the specified row,
1424 * start at the implicit given position */
1425 void LyXText::AppendParagraph(Row * row) const
1427 bool not_ready = true;
1429 // The last character position of a paragraph is an invariant so we can
1430 // safely get it here. (Asger)
1431 int lastposition = row->par->Last();
1434 // Get the next breakpoint
1435 int z = NextBreakPoint(row, paperwidth);
1439 // Insert the new row
1440 if (z < lastposition) {
1442 InsertRow(row, row->par, z);
1449 // Set the dimensions of the row
1450 tmprow->fill = Fill(tmprow, paperwidth);
1451 SetHeightOfRow(tmprow);
1453 } while (not_ready);
1457 void LyXText::BreakAgain(Row * row) const
1459 bool not_ready = true;
1462 /* get the next breakpoint */
1463 LyXParagraph::size_type z =
1464 NextBreakPoint(row, paperwidth);
1467 if (z < row->par->Last() ) {
1468 if (!row->next || (row->next && row->next->par != row->par)) {
1471 InsertRow(row, row->par, z);
1478 not_ready = false; // the rest will not change
1484 /* if there are some rows too much, delete them */
1485 /* only if you broke the whole paragraph! */
1486 Row * tmprow2 = row;
1487 while (tmprow2->next && tmprow2->next->par == row->par) {
1488 tmprow2 = tmprow2->next;
1490 while (tmprow2 != row) {
1491 tmprow2 = tmprow2->previous;
1492 RemoveRow(tmprow2->next);
1497 /* set the dimensions of the row */
1498 tmprow->fill = Fill(tmprow, paperwidth);
1499 SetHeightOfRow(tmprow);
1500 } while (not_ready);
1504 /* this is just a little changed version of break again */
1505 void LyXText::BreakAgainOneRow(Row * row)
1507 /* get the next breakpoint */
1508 LyXParagraph::size_type z = NextBreakPoint(row, paperwidth);
1511 if (z < row->par->Last() ) {
1512 if (!row->next || (row->next && row->next->par != row->par)) {
1513 /* insert a new row */
1515 InsertRow(row, row->par, z);
1527 /* if there are some rows too much, delete them */
1528 /* only if you broke the whole paragraph! */
1529 Row * tmprow2 = row;
1530 while (tmprow2->next && tmprow2->next->par == row->par) {
1531 tmprow2 = tmprow2->next;
1533 while (tmprow2 != row) {
1534 tmprow2 = tmprow2->previous;
1535 RemoveRow(tmprow2->next);
1539 /* set the dimensions of the row */
1540 tmprow->fill = Fill(tmprow, paperwidth);
1541 SetHeightOfRow(tmprow);
1545 void LyXText::BreakParagraph(char keep_layout)
1547 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
1548 cursor.par->GetLayout());
1550 /* table stuff -- begin */
1551 if (cursor.par->table) {
1552 // breaking of tables is only allowed at the beginning or the end */
1553 if (cursor.pos && cursor.pos < cursor.par->size() &&
1554 !cursor.par->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par, cursor.pos)))
1555 return; // no breaking of tables allowed
1557 /* table stuff -- end */
1559 // this is only allowed, if the current paragraph is not empty or caption
1560 if ((cursor.par->Last() <= 0 && !cursor.par->IsDummy())
1562 layout.labeltype!= LABEL_SENSITIVE)
1565 SetUndo(Undo::INSERT,
1566 cursor.par->ParFromPos(cursor.pos)->previous,
1567 cursor.par->ParFromPos(cursor.pos)->next);
1569 /* table stuff -- begin */
1570 if (cursor.par->table) {
1571 int cell = NumberOfCell(cursor.par, cursor.pos);
1572 if (cursor.par->table->ShouldBeVeryLastCell(cell))
1573 SetCursor(cursor.par, cursor.par->text.size());
1575 /* table stuff -- end */
1577 // please break always behind a space
1578 if (cursor.pos < cursor.par->Last()
1579 && cursor.par->IsLineSeparator(cursor.pos))
1582 // break the paragraph
1586 keep_layout = layout.isEnvironment();
1587 cursor.par->BreakParagraph(cursor.pos, keep_layout);
1589 /* table stuff -- begin */
1590 if (cursor.par->table){
1591 // the table should stay with the contents
1593 cursor.par->Next()->table = cursor.par->table;
1594 cursor.par->table = 0;
1597 /* table stuff -- end */
1599 // well this is the caption hack since one caption is really enough
1600 if (layout.labeltype == LABEL_SENSITIVE){
1602 cursor.par->SetLayout(0); // set to standard-layout
1604 cursor.par->Next()->SetLayout(0); // set to standard-layout
1607 /* if the cursor is at the beginning of a row without prior newline,
1609 * This touches only the screen-update. Otherwise we would may have
1610 * an empty row on the screen */
1611 if (cursor.pos && !cursor.row->par->IsNewline(cursor.row->pos -1) &&
1612 cursor.row->pos == cursor.pos) {
1616 status = LyXText::NEED_MORE_REFRESH;
1617 refresh_row = cursor.row;
1618 refresh_y = cursor.y - cursor.row->baseline;
1620 // Do not forget the special right address boxes
1621 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1622 while (refresh_row->previous &&
1623 refresh_row->previous->par == refresh_row->par) {
1624 refresh_row = refresh_row->previous;
1625 refresh_y -= refresh_row->height;
1628 RemoveParagraph(cursor.row);
1630 // set the dimensions of the cursor row
1631 cursor.row->fill = Fill(cursor.row, paperwidth);
1633 SetHeightOfRow(cursor.row);
1635 while (!cursor.par->Next()->table && cursor.par->Next()->Last()
1636 && cursor.par->Next()->IsNewline(0))
1637 cursor.par->Next()->Erase(0);
1639 InsertParagraph(cursor.par->Next(), cursor.row);
1641 UpdateCounters(cursor.row->previous);
1643 /* This check is necessary. Otherwise the new empty paragraph will
1644 * be deleted automatically. And it is more friendly for the user! */
1646 SetCursor(cursor.par->Next(), 0);
1648 SetCursor(cursor.par, 0);
1650 if (cursor.row->next)
1651 BreakAgain(cursor.row->next);
1657 void LyXText::OpenFootnote()
1659 LyXParagraph * endpar,* tmppar;
1662 LyXParagraph * par = cursor.par->ParFromPos(cursor.pos);
1664 /* if there is no footnote in this paragraph, just return. */
1666 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1669 /* ok, move the cursor right before the footnote */
1671 /* just a little faster than using CursorRight() */
1672 for (cursor.pos = 0;
1673 cursor.par->ParFromPos(cursor.pos) != par; cursor.pos++);
1674 /* now the cursor is at the beginning of the physical par */
1675 SetCursor(cursor.par,
1676 cursor.pos + cursor.par->ParFromPos(cursor.pos)->text.size());
1678 /* the cursor must be exactly before the footnote */
1679 par = cursor.par->ParFromPos(cursor.pos);
1681 status = LyXText::NEED_MORE_REFRESH;
1682 refresh_row = cursor.row;
1683 refresh_y = cursor.y - cursor.row->baseline;
1685 tmppar = cursor.par;
1686 endpar = cursor.par->Next();
1689 tmppar->OpenFootnote(cursor.pos);
1690 RemoveParagraph(row);
1691 /* set the dimensions of the cursor row */
1692 row->fill = Fill(row, paperwidth);
1693 SetHeightOfRow(row);
1694 tmppar = tmppar->Next();
1696 while (tmppar != endpar) {
1698 InsertParagraph(tmppar, row);
1699 while (row->next && row->next->par == tmppar)
1701 tmppar = tmppar->Next();
1704 SetCursor(par->next, 0);
1705 sel_cursor = cursor;
1709 /* table stuff -- begin*/
1711 void LyXText::TableFeatures(int feature, string const & val) const
1713 if (!cursor.par->table)
1714 return; /* this should never happen */
1716 int actCell = NumberOfCell(cursor.par, cursor.pos);
1717 SetUndo(Undo::FINISH,
1718 cursor.par->ParFromPos(cursor.pos)->previous,
1719 cursor.par->ParFromPos(cursor.pos)->next);
1722 case LyXTable::SET_PWIDTH:
1723 cursor.par->table->SetPWidth(actCell, val);
1725 case LyXTable::SET_SPECIAL_COLUMN:
1726 case LyXTable::SET_SPECIAL_MULTI:
1727 cursor.par->table->SetAlignSpecial(actCell, val, feature);
1736 void LyXText::TableFeatures(int feature) const
1739 int setAlign = LYX_ALIGN_LEFT;
1743 if (!cursor.par->table)
1744 return; /* this should never happen */
1746 int actCell = NumberOfCell(cursor.par, cursor.pos);
1747 SetUndo(Undo::FINISH,
1748 cursor.par->ParFromPos(cursor.pos)->previous,
1749 cursor.par->ParFromPos(cursor.pos)->next);
1752 case LyXTable::ALIGN_LEFT:
1753 setAlign= LYX_ALIGN_LEFT;
1755 case LyXTable::ALIGN_RIGHT:
1756 setAlign= LYX_ALIGN_RIGHT;
1758 case LyXTable::ALIGN_CENTER:
1759 setAlign= LYX_ALIGN_CENTER;
1765 case LyXTable::APPEND_ROW: {
1766 LyXParagraph::size_type pos = cursor.pos;
1768 /* move to the next row */
1769 int cell_org = actCell;
1770 int cell = cell_org;
1772 // if there is a ContRow following this row I have to add
1773 // the row after the ContRow's
1774 if ((pos < cursor.par->Last()) &&
1775 cursor.par->table->RowHasContRow(cell_org)) {
1776 while((pos < cursor.par->Last()) &&
1777 !cursor.par->table->IsContRow(cell)) {
1778 while (pos < cursor.par->Last() &&
1779 !cursor.par->IsNewline(pos))
1781 if (pos < cursor.par->Last())
1785 while((pos < cursor.par->Last()) &&
1786 cursor.par->table->IsContRow(cell)) {
1787 while (pos < cursor.par->Last() &&
1788 !cursor.par->IsNewline(pos))
1790 if (pos < cursor.par->Last())
1795 if (pos < cursor.par->Last())
1798 while (pos < cursor.par->Last() &&
1799 (cell == cell_org || !cursor.par->table->IsFirstCell(cell))){
1800 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1802 if (pos < cursor.par->Last())
1807 /* insert the new cells */
1808 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1809 for (int i = 0; i < number; ++i)
1810 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1812 /* append the row into the table */
1813 cursor.par->table->AppendRow(cell_org);
1817 case LyXTable::APPEND_CONT_ROW: {
1818 LyXParagraph::size_type pos = cursor.pos;
1819 /* move to the next row */
1820 int cell_org = actCell;
1821 int cell = cell_org;
1823 // if there is already a controw but not for this cell
1824 // the AppendContRow sets only the right values but does
1825 // not actually add a row
1826 if (cursor.par->table->RowHasContRow(cell_org) &&
1827 (cursor.par->table->CellHasContRow(cell_org)<0)) {
1828 cursor.par->table->AppendContRow(cell_org);
1832 while (pos < cursor.par->Last() &&
1834 || !cursor.par->table->IsFirstCell(cell))){
1835 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1837 if (pos < cursor.par->Last())
1842 /* insert the new cells */
1843 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1844 for (int i = 0; i < number; ++i)
1845 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1847 /* append the row into the table */
1848 cursor.par->table->AppendContRow(cell_org);
1852 case LyXTable::APPEND_COLUMN: {
1853 LyXParagraph::size_type pos = 0;
1854 int cell_org = actCell;
1857 if (pos && (cursor.par->IsNewline(pos-1))){
1858 if (cursor.par->table->AppendCellAfterCell(cell_org, cell)){
1859 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1860 if (pos <= cursor.pos)
1867 } while (pos <= cursor.par->Last());
1868 /* remember that the very last cell doesn't end with a newline.
1869 This saves one byte memory per table ;-) */
1870 if (cursor.par->table->AppendCellAfterCell(cell_org, cell))
1871 cursor.par->InsertChar(cursor.par->Last(), LyXParagraph::META_NEWLINE);
1873 /* append the column into the table */
1874 cursor.par->table->AppendColumn(cell_org);
1879 case LyXTable::DELETE_ROW:
1880 if (current_view->the_locking_inset)
1881 current_view->unlockInset(current_view->the_locking_inset);
1882 RemoveTableRow(&cursor);
1886 case LyXTable::DELETE_COLUMN: {
1887 LyXParagraph::size_type pos = 0;
1888 int cell_org = actCell;
1890 if (current_view->the_locking_inset)
1891 current_view->unlockInset(current_view->the_locking_inset);
1893 if (!pos || (cursor.par->IsNewline(pos-1))){
1894 if (cursor.par->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
1896 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1897 cursor.par->Erase(pos);
1898 if (pos < cursor.par->Last())
1899 cursor.par->Erase(pos);
1901 cursor.par->Erase(pos - 1); // the missing newline at the end of a table
1902 --pos; // because of pos++ below
1907 } while (pos <= cursor.par->Last());
1909 /* delete the column from the table */
1910 cursor.par->table->DeleteColumn(cell_org);
1912 /* set the cursor to the beginning of the table, where else? */
1917 case LyXTable::TOGGLE_LINE_TOP:
1918 lineSet = !cursor.par->table->TopLine(actCell);
1920 cursor.par->table->SetTopLine(actCell, lineSet);
1922 LyXParagraph::size_type i;
1924 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
1925 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
1926 cursor.par->table->SetTopLine(n, lineSet);
1934 case LyXTable::TOGGLE_LINE_BOTTOM:
1935 lineSet = !cursor.par->table->BottomLine(actCell);
1937 cursor.par->table->SetBottomLine(actCell, lineSet);
1939 LyXParagraph::size_type i;
1941 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
1942 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
1943 cursor.par->table->SetBottomLine(n, lineSet);
1951 case LyXTable::TOGGLE_LINE_LEFT:
1952 lineSet = !cursor.par->table->LeftLine(actCell);
1954 cursor.par->table->SetLeftLine(actCell, lineSet);
1956 LyXParagraph::size_type i;
1958 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
1959 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1960 cursor.par->table->SetLeftLine(n, lineSet);
1968 case LyXTable::TOGGLE_LINE_RIGHT:
1969 lineSet = !cursor.par->table->RightLine(actCell);
1971 cursor.par->table->SetRightLine(actCell, lineSet);
1974 LyXParagraph::size_type i = sel_start_cursor.pos;
1975 for (; i <= sel_end_cursor.pos; ++i) {
1976 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1977 cursor.par->table->SetRightLine(n, lineSet);
1985 case LyXTable::ALIGN_LEFT:
1986 case LyXTable::ALIGN_RIGHT:
1987 case LyXTable::ALIGN_CENTER:
1989 cursor.par->table->SetAlignment(actCell, setAlign);
1992 LyXParagraph::size_type i = sel_start_cursor.pos;
1993 for (; i <= sel_end_cursor.pos; ++i) {
1994 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1995 cursor.par->table->SetAlignment(n, setAlign);
2003 case LyXTable::DELETE_TABLE:
2004 SetCursorIntern(cursor.par, 0);
2005 delete cursor.par->table;
2006 cursor.par->table = 0;
2007 // temporary: Should put table in simple_cut_buffer (with before and after
2008 // dummy-paragraph !!
2009 // not necessar anymore with UNDO :)
2010 for (LyXParagraph::size_type i =
2011 cursor.par->text.size() - 1; i >= 0; --i)
2012 cursor.par->Erase(i);
2016 case LyXTable::MULTICOLUMN: {
2018 // check wether we are completly in a multicol
2019 int multicol = cursor.par->table->IsMultiColumn(actCell);
2020 if (multicol && selection && sel_start_cursor.row == sel_end_cursor.row){
2021 multicol = NumberOfCell(sel_start_cursor.par, sel_start_cursor.pos)
2022 == NumberOfCell(sel_end_cursor.par, sel_end_cursor.pos);
2026 int newlines = cursor.par->table->UnsetMultiColumn(actCell);
2027 LyXParagraph::size_type pos = cursor.pos;
2028 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
2030 for (; newlines; --newlines)
2031 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
2036 // selection must be in one row (or no selection)
2038 cursor.par->table->SetMultiColumn(NumberOfCell(cursor.par,
2045 if (sel_start_cursor.row == sel_end_cursor.row){
2046 LyXParagraph::size_type i;
2048 for (i = sel_start_cursor.pos;
2049 i < sel_end_cursor.pos; ++i){
2050 if (sel_start_cursor.par->IsNewline(i)){
2051 sel_start_cursor.par->Erase(i);
2052 // check for double-blanks
2053 if ((i && !sel_start_cursor.par->IsLineSeparator(i-1))
2055 (i < sel_start_cursor.par->Last()
2056 && !sel_start_cursor.par->IsLineSeparator(i)))
2057 sel_start_cursor.par->InsertChar(i, ' ');
2059 sel_end_cursor.pos--;
2066 SetMultiColumn(NumberOfCell(sel_start_cursor.par,
2067 sel_start_cursor.pos),
2069 cursor.pos = sel_start_cursor.pos;
2074 WriteAlert(_("Impossible Operation!"),
2075 _("Multicolumns can only be horizontally."),
2082 case LyXTable::SET_ALL_LINES:
2084 case LyXTable::UNSET_ALL_LINES:
2086 cursor.par->table->SetAllLines(NumberOfCell(cursor.par,
2090 LyXParagraph::size_type i;
2092 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2093 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2094 cursor.par->table->SetAllLines(n, setLines);
2101 case LyXTable::SET_LONGTABLE:
2102 cursor.par->table->SetLongTable(true);
2104 case LyXTable::UNSET_LONGTABLE:
2105 cursor.par->table->SetLongTable(false);
2107 case LyXTable::SET_ROTATE_TABLE:
2108 cursor.par->table->SetRotateTable(true);
2110 case LyXTable::UNSET_ROTATE_TABLE:
2111 cursor.par->table->SetRotateTable(false);
2113 case LyXTable::SET_ROTATE_CELL:
2115 cursor.par->table->SetRotateCell(actCell, true);
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->SetRotateCell(n, true);
2127 case LyXTable::UNSET_ROTATE_CELL:
2129 cursor.par->table->SetRotateCell(actCell, false);
2132 LyXParagraph::size_type i = sel_start_cursor.pos;
2133 for (; i <= sel_end_cursor.pos; ++i) {
2134 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2135 cursor.par->table->SetRotateCell(n, false);
2141 case LyXTable::SET_LINEBREAKS:
2142 what = !cursor.par->table->Linebreaks(cursor.par->table->FirstVirtualCell(actCell));
2144 cursor.par->table->SetLinebreaks(actCell, what);
2146 LyXParagraph::size_type i;
2148 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2149 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2150 cursor.par->table->SetLinebreaks(n, what);
2156 case LyXTable::SET_LTFIRSTHEAD:
2157 cursor.par->table->SetLTHead(actCell, true);
2159 case LyXTable::SET_LTHEAD:
2160 cursor.par->table->SetLTHead(actCell, false);
2162 case LyXTable::SET_LTFOOT:
2163 cursor.par->table->SetLTFoot(actCell, false);
2165 case LyXTable::SET_LTLASTFOOT:
2166 cursor.par->table->SetLTFoot(actCell, true);
2168 case LyXTable::SET_LTNEWPAGE:
2169 what = !cursor.par->table->LTNewPage(actCell);
2170 cursor.par->table->SetLTNewPage(actCell, what);
2176 void LyXText::InsertCharInTable(char c)
2181 bool jumped_over_space;
2183 /* first check, if there will be two blanks together or a blank at
2184 * the beginning of a paragraph.
2185 * I decided to handle blanks like normal characters, the main
2186 * difference are the special checks when calculating the row.fill
2187 * (blank does not count at the end of a row) and the check here */
2189 LyXFont realtmpfont = real_current_font;
2190 LyXFont rawtmpfont = current_font; /* store the current font.
2191 * This is because of the use
2192 * of cursor movements. The moving
2193 * cursor would refresh the
2196 // Get the font that is used to calculate the baselineskip
2197 LyXParagraph::size_type const lastpos =
2199 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2201 jumped_over_space = false;
2202 if (IsLineSeparatorChar(c)) {
2204 /* avoid double blanks but insert the new blank because
2205 * of a possible font change */
2206 if (cursor.pos < lastpos &&
2207 cursor.par->IsLineSeparator(cursor.pos))
2209 cursor.par->Erase(cursor.pos);
2210 jumped_over_space = true;
2212 else if ((cursor.pos > 0 &&
2213 cursor.par->IsLineSeparator(cursor.pos - 1))
2214 || (cursor.pos > 0 && cursor.par->IsNewline(cursor.pos - 1))
2215 || (cursor.pos == 0 &&
2216 !(cursor.par->Previous()
2217 && cursor.par->Previous()->footnoteflag
2218 == LyXParagraph::OPEN_FOOTNOTE)))
2221 else if (IsNewlineChar(c)) {
2222 if (!IsEmptyTableCell()) {
2223 TableFeatures(LyXTable::APPEND_CONT_ROW);
2230 y = cursor.y - row->baseline;
2231 if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset
2232 * already inserted the character */
2233 cursor.par->InsertChar(cursor.pos, c);
2234 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2236 if (!jumped_over_space) {
2237 /* refresh the positions */
2239 while (tmprow->next && tmprow->next->par == row->par) {
2240 tmprow = tmprow->next;
2247 CheckParagraphInTable(cursor.par, cursor.pos);
2249 current_font = rawtmpfont;
2250 real_current_font = realtmpfont;
2252 /* check, whether the last character's font has changed. */
2253 if (cursor.pos && cursor.pos == cursor.par->Last()
2254 && rawparfont != rawtmpfont)
2255 RedoHeightOfParagraph(cursor);
2259 void LyXText::CheckParagraphInTable(LyXParagraph * par,
2260 LyXParagraph::size_type pos)
2263 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
2264 par->GetInset(pos) && par->GetInset(pos)->display()){
2265 par->GetInset(pos)->display(false);
2269 Row * row = GetRow(par, pos, y);
2271 int tmpheight = row->height;
2272 SetHeightOfRow(row);
2274 LyXParagraph::size_type tmp_pos = pos;
2275 /* update the table information */
2276 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2278 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2279 WidthOfCell(par, tmp_pos))) {
2280 LyXCursor tmpcursor = cursor;
2281 SetCursorIntern(par, pos);
2282 /* make a complete redraw */
2283 RedoDrawingOfParagraph(cursor);
2287 /* redraw only the row */
2288 LyXCursor tmpcursor = cursor;
2289 SetCursorIntern(par, pos);
2291 refresh_x = cursor.x;
2293 refresh_pos = cursor.pos;
2296 if (tmpheight == row->height)
2297 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2299 status = LyXText::NEED_MORE_REFRESH;
2301 SetCursorIntern(cursor.par, cursor.pos);
2305 void LyXText::BackspaceInTable()
2307 Row * tmprow, * row;
2310 LyXFont rawtmpfont = current_font;
2311 LyXFont realtmpfont = real_current_font;
2313 // Get the font that is used to calculate the baselineskip
2314 int const lastpos = cursor.par->Last();
2315 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2317 if (cursor.pos == 0) {
2318 /* no pasting of table paragraphs */
2323 /* this is the code for a normal backspace, not pasting
2325 SetUndo(Undo::DELETE,
2326 cursor.par->ParFromPos(cursor.pos)->previous,
2327 cursor.par->ParFromPos(cursor.pos)->next);
2331 /* some insets are undeletable here */
2332 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
2333 if (!cursor.par->GetInset(cursor.pos)->Deletable())
2338 y = cursor.y - row->baseline;
2340 /* some special code when deleting a newline. */
2341 if (cursor.par->IsNewline(cursor.pos)) {
2346 cursor.par->Erase(cursor.pos);
2348 /* refresh the positions */
2350 while (tmprow->next && tmprow->next->par == row->par) {
2351 tmprow = tmprow->next;
2355 /* delete superfluous blanks */
2356 if (cursor.pos < cursor.par->Last() - 1 &&
2357 (cursor.par->IsLineSeparator(cursor.pos))) {
2359 if (cursor.pos == BeginningOfMainBody(cursor.par)
2361 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
2362 cursor.par->Erase(cursor.pos);
2363 /* refresh the positions */
2365 while (tmprow->next &&
2366 tmprow->next->par == row->par) {
2367 tmprow = tmprow->next;
2370 if (cursor.pos) /* move one character left */
2376 CheckParagraphInTable(cursor.par, cursor.pos);
2378 /* check, wether the last characters font has changed. */
2379 if (cursor.pos && cursor.pos == cursor.par->Last()
2380 && rawparfont != rawtmpfont)
2381 RedoHeightOfParagraph(cursor);
2383 /* restore the current font
2384 * That is what a user expects! */
2385 current_font = rawtmpfont;
2386 real_current_font = realtmpfont;
2388 SetCursorIntern(cursor.par, cursor.pos);
2391 /* table stuff -- end*/
2394 /* just a macro to make some thing easier. */
2395 void LyXText::RedoParagraph() const
2398 // I suspect this version will work
2401 RedoParagraphs(cursor, cursor.par->Next());
2402 SetCursorIntern(cursor.par, cursor.pos);
2404 LyXCursor tmpcursor = cursor;
2406 RedoParagraphs(cursor, cursor.par->Next());
2407 SetCursorIntern(tmpcursor.par, tmpcursor.pos);
2412 /* insert a character, moves all the following breaks in the
2413 * same Paragraph one to the right and make a rebreak */
2414 void LyXText::InsertChar(char c)
2416 SetUndo(Undo::INSERT,
2417 cursor.par->ParFromPos(cursor.pos)->previous,
2418 cursor.par->ParFromPos(cursor.pos)->next);
2420 /* When the free-spacing option is set for the current layout,
2421 * all spaces are converted to protected spaces. */
2422 bool freeSpacingBo =
2423 textclasslist.Style(parameters->textclass,
2424 cursor.row->par->GetLayout()).free_spacing;
2426 if (freeSpacingBo && IsLineSeparatorChar(c)
2427 && (!cursor.pos || cursor.par->IsLineSeparator(cursor.pos - 1)))
2428 c = LyXParagraph::META_PROTECTED_SEPARATOR;
2430 /* table stuff -- begin*/
2431 if (cursor.par->table) {
2432 InsertCharInTable(c);
2436 /* table stuff -- end*/
2438 /* First check, if there will be two blanks together or a blank at
2439 the beginning of a paragraph.
2440 I decided to handle blanks like normal characters, the main
2441 difference are the special checks when calculating the row.fill
2442 (blank does not count at the end of a row) and the check here */
2444 // The bug is triggered when we type in a description environment:
2445 // The current_font is not changed when we go from label to main text
2446 // and it should (along with realtmpfont) when we type the space.
2447 #ifdef WITH_WARNINGS
2448 #warning There is a bug here! (Asger)
2451 LyXFont realtmpfont = real_current_font;
2452 LyXFont rawtmpfont = current_font; /* store the current font.
2453 * This is because of the use
2454 * of cursor movements. The moving
2455 * cursor would refresh the
2458 // Get the font that is used to calculate the baselineskip
2459 LyXParagraph::size_type lastpos = cursor.par->Last();
2460 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2462 bool jumped_over_space = false;
2464 if (IsLineSeparatorChar(c)) {
2465 #ifndef FIX_DOUBLE_SPACE
2466 if (cursor.pos < lastpos
2467 && cursor.par->IsLineSeparator(cursor.pos)) {
2468 /* the user inserted a space before a space. So we
2469 * will just make a CursorRight. BUT: The font of this
2470 * space should be set to current font. That is why
2471 * we need to rebreak perhaps. If there is a protected
2472 * blank at the end of a row we have to force
2475 current_view->owner()->getMiniBuffer()
2476 ->Set(_("You cannot type two spaces this way. "
2477 " Please read the Tutorial."));
2479 // How can this ever happen?
2480 if (cursor.pos == RowLast(cursor.row)
2481 && !IsLineSeparatorChar(c))
2482 cursor.row->fill = -1; // force rebreak
2483 cursor.par->Erase(cursor.pos);
2484 jumped_over_space = true;
2486 // Seems to me that this works just as well.
2494 && cursor.par->IsLineSeparator(cursor.pos - 1))
2496 && cursor.par->IsNewline(cursor.pos - 1))
2498 && !(cursor.par->Previous()
2499 && cursor.par->Previous()->footnoteflag
2500 == LyXParagraph::OPEN_FOOTNOTE))) {
2501 if (cursor.pos == 0 )
2502 current_view->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2504 current_view->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2508 } else if (IsNewlineChar(c)) {
2509 if (cursor.par->FirstPhysicalPar() == cursor.par
2510 && cursor.pos <= BeginningOfMainBody(cursor.par)) {
2514 /* No newline at first position
2515 * of a paragraph or behind labels.
2516 * TeX does not allow that. */
2518 if (cursor.pos < cursor.par->Last() &&
2519 cursor.par->IsLineSeparator(cursor.pos))
2520 CursorRightIntern(); // newline always after a blank!
2521 cursor.row->fill = -1; // to force a new break
2524 // the display inset stuff
2525 if (cursor.row->par->GetChar(cursor.row->pos) == LyXParagraph::META_INSET
2526 && cursor.row->par->GetInset(cursor.row->pos)
2527 && cursor.row->par->GetInset(cursor.row->pos)->display())
2528 cursor.row->fill = -1; // to force a new break
2530 // get the cursor row fist
2531 Row * row = cursor.row;
2532 long y = cursor.y - row->baseline;
2533 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2534 * already insertet the character */
2535 cursor.par->InsertChar(cursor.pos, c);
2536 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2538 if (!jumped_over_space) {
2539 // refresh the positions
2541 while (tmprow->next && tmprow->next->par == row->par) {
2542 tmprow = tmprow->next;
2547 // Is there a break one row above
2548 if ((cursor.par->IsLineSeparator(cursor.pos)
2549 || cursor.par->IsNewline(cursor.pos)
2550 || cursor.row->fill == -1)
2551 && row->previous && row->previous->par == row->par) {
2552 LyXParagraph::size_type z = NextBreakPoint(row->previous,
2554 if ( z >= row->pos) {
2557 // set the dimensions of the row above
2558 row->previous->fill = Fill(row->previous, paperwidth);
2560 SetHeightOfRow(row->previous);
2562 y -= row->previous->height;
2564 refresh_row = row->previous;
2565 status = LyXText::NEED_MORE_REFRESH;
2567 BreakAgainOneRow(row);
2569 current_font = rawtmpfont;
2570 real_current_font = realtmpfont;
2571 SetCursor(cursor.par, cursor.pos + 1, false);
2572 /* cursor MUST be in row now */
2574 if (row->next && row->next->par == row->par)
2575 need_break_row = row->next;
2579 // check, wether the last characters font has changed.
2580 if (cursor.pos && cursor.pos == cursor.par->Last()
2581 && rawparfont != rawtmpfont)
2582 RedoHeightOfParagraph(cursor);
2589 /* recalculate the fill of the row */
2590 if (row->fill >= 0) /* needed because a newline
2591 * will set fill to -1. Otherwise
2592 * we would not get a rebreak! */
2593 row->fill = Fill(row, paperwidth);
2594 if (row->fill < 0 ) {
2597 refresh_x = cursor.x;
2598 refresh_pos = cursor.pos;
2599 status = LyXText::NEED_MORE_REFRESH;
2600 BreakAgainOneRow(row);
2601 /* will the cursor be in another row now? */
2602 if (RowLast(row) <= cursor.pos + 1 && row->next) {
2603 if (row->next && row->next->par == row->par)
2607 BreakAgainOneRow(row);
2609 current_font = rawtmpfont;
2610 real_current_font = realtmpfont;
2611 SetCursor(cursor.par, cursor.pos + 1, false);
2612 if (row->next && row->next->par == row->par)
2613 need_break_row = row->next;
2618 refresh_x = cursor.x;
2620 refresh_pos = cursor.pos;
2622 int tmpheight = row->height;
2623 SetHeightOfRow(row);
2624 if (tmpheight == row->height)
2625 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2627 status = LyXText::NEED_MORE_REFRESH;
2629 current_font = rawtmpfont;
2630 real_current_font = realtmpfont;
2631 SetCursor(cursor.par, cursor.pos + 1, false);
2634 /* check, wether the last characters font has changed. */
2635 if (cursor.pos && cursor.pos == cursor.par->Last()
2636 && rawparfont != rawtmpfont) {
2637 RedoHeightOfParagraph(cursor);
2639 /* now the special right address boxes */
2640 if (textclasslist.Style(parameters->textclass,
2641 cursor.par->GetLayout()).margintype
2642 == MARGIN_RIGHT_ADDRESS_BOX) {
2643 RedoDrawingOfParagraph(cursor);
2651 void LyXText::charInserted()
2653 // Here we could call FinishUndo for every 20 characters inserted.
2654 // This is from my experience how emacs does it.
2655 static unsigned int counter = 0;
2664 void LyXText::PrepareToPrint(Row * row, float & x,
2665 float & fill_separator,
2667 float & fill_label_hfill,
2672 float w = row->fill;
2674 fill_label_hfill = 0;
2676 fill_label_hfill = 0;
2678 LyXDirection direction = row->par->getParDirection();
2680 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
2681 x = RightMargin(row);
2682 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2683 LyXFont font(LyXFont::ALL_SANE);
2684 font.setSize(LyXFont::SIZE_SMALL);
2685 x += font.textWidth("Mwide-figM", 10);
2689 x = LeftMargin(row);
2691 /* is there a manual margin with a manual label */
2692 if (textclasslist.Style(parameters->textclass,
2693 row->par->GetLayout()).margintype == MARGIN_MANUAL
2694 && textclasslist.Style(parameters->textclass,
2695 row->par->GetLayout()).labeltype == LABEL_MANUAL) {
2697 nlh = NumberOfLabelHfills(row) + 1; /* one more since labels
2698 * are left aligned*/
2699 if (nlh && !row->par->GetLabelWidthString().empty()) {
2700 fill_label_hfill = LabelFill(row) / nlh;
2704 /* are there any hfills in the row? */
2705 nh = NumberOfHfills(row);
2707 /* table stuff -- begin*/
2708 if (row->par->table) {
2709 w = paperwidth - row->par->table->WidthOfTable()
2710 - x - RightMargin(row);
2711 nh = 0; /* ignore hfills in tables */
2713 /* table stuff -- end*/
2718 /* is it block, flushleft or flushright?
2719 * set x how you need it */
2721 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2722 align = textclasslist.Style(parameters->textclass, row->par->GetLayout()).align;
2724 align = row->par->FirstPhysicalPar()->align;
2726 /* center displayed insets */
2727 if (row->par->GetChar(row->pos) == LyXParagraph::META_INSET
2728 && row->par->GetInset(row->pos)
2729 && row->par->GetInset(row->pos)->display())
2730 align = LYX_ALIGN_CENTER;
2733 case LYX_ALIGN_BLOCK:
2734 ns = NumberOfSeparators(row);
2735 if (ns && row->next && row->next->par == row->par &&
2736 !(row->next->par->IsNewline(row->next->pos-1))
2737 && !(row->next->par->GetChar(row->next->pos) == LyXParagraph::META_INSET
2738 && row->next->par->GetInset(row->next->pos)
2739 && row->next->par->GetInset(row->next->pos)->display())
2741 fill_separator = w / ns;
2742 else if (direction == LYX_DIR_RIGHT_TO_LEFT)
2745 case LYX_ALIGN_RIGHT:
2748 case LYX_ALIGN_CENTER:
2756 ComputeBidiTables(row);
2757 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
2758 LyXParagraph::size_type main_body =
2759 BeginningOfMainBody(row->par);
2760 LyXParagraph::size_type last = RowLast(row);
2762 if (row->pos <= last
2764 && last != vis2log(last)
2765 && row->par->IsLineSeparator(last)) {
2766 if (!(main_body > 0 && main_body-1 == last))
2767 x -= fill_separator+SingleWidth(row->par,last);
2768 } else if (main_body > 0 &&
2769 (main_body-1 > last ||
2770 !row->par->IsLineSeparator(main_body-1))) {
2771 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
2772 row->par->GetLayout());
2773 x += GetFont(row->par, -2).stringWidth(layout.labelsep);
2774 if (main_body-1 <= last)
2775 x += fill_label_hfill;
2780 /* important for the screen */
2783 /* the cursor set functions have a special mechanism. When they
2784 * realize, that you left an empty paragraph, they will delete it.
2785 * They also delete the corresponding row */
2787 void LyXText::CursorRightOneWord() const
2789 // treat floats, HFills and Insets as words
2790 LyXCursor tmpcursor = cursor;
2792 if (tmpcursor.pos == tmpcursor.par->Last()
2793 && tmpcursor.par->Next())
2795 tmpcursor.par = tmpcursor.par->Next();
2800 // Skip through initial nonword stuff.
2801 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2802 ! tmpcursor.par->IsWord( tmpcursor.pos ) )
2804 // printf("Current pos1 %d", tmpcursor.pos) ;
2808 // Advance through word.
2809 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2810 tmpcursor.par->IsWord( tmpcursor.pos ) )
2812 // printf("Current pos2 %d", tmpcursor.pos) ;
2817 SetCursor(tmpcursor.par, tmpcursor.pos);
2821 void LyXText::CursorTab() const
2823 if (cursor.par->table) {
2824 int cell = NumberOfCell(cursor.par, cursor.pos);
2825 while(cursor.par->table->IsContRow(cell)) {
2827 cell = NumberOfCell(cursor.par, cursor.pos);
2829 if (cursor.par->table->ShouldBeVeryLastCell(cell))
2830 TableFeatures(LyXTable::APPEND_ROW);
2832 LyXCursor tmpcursor = cursor;
2833 while (tmpcursor.pos < tmpcursor.par->Last()
2834 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2837 if (tmpcursor.pos == tmpcursor.par->Last()){
2838 if (tmpcursor.par->Next()) {
2839 tmpcursor.par = tmpcursor.par->Next();
2845 SetCursor(tmpcursor.par, tmpcursor.pos);
2846 if (cursor.par->table) {
2847 int cell = NumberOfCell(cursor.par, cursor.pos);
2848 while (cursor.par->table->IsContRow(cell) &&
2849 !cursor.par->table->ShouldBeVeryLastCell(cell)) {
2851 while (tmpcursor.pos < tmpcursor.par->Last()
2852 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2855 if (tmpcursor.pos == tmpcursor.par->Last()){
2856 if (tmpcursor.par->Next()) {
2857 tmpcursor.par = tmpcursor.par->Next();
2863 SetCursor(tmpcursor.par, tmpcursor.pos);
2864 cell = NumberOfCell(cursor.par, cursor.pos);
2870 /* -------> Skip initial whitespace at end of word and move cursor to *start*
2871 of prior word, not to end of next prior word. */
2873 void LyXText::CursorLeftOneWord() const
2875 // treat HFills, floats and Insets as words
2876 LyXCursor tmpcursor = cursor;
2877 while (tmpcursor.pos
2878 && (tmpcursor.par->IsSeparator(tmpcursor.pos - 1)
2879 || tmpcursor.par->IsKomma(tmpcursor.pos - 1))
2880 && !(tmpcursor.par->IsHfill(tmpcursor.pos - 1)
2881 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2882 || tmpcursor.par->IsInset(tmpcursor.pos - 1)))
2886 && (tmpcursor.par->IsInset(tmpcursor.pos - 1)
2887 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2888 || tmpcursor.par->IsHfill(tmpcursor.pos - 1))) {
2890 } else if (!tmpcursor.pos) {
2891 if (tmpcursor.par->Previous()){
2892 tmpcursor.par = tmpcursor.par->Previous();
2893 tmpcursor.pos = tmpcursor.par->Last();
2895 } else { // Here, tmpcursor != 0
2896 while (tmpcursor.pos > 0 &&
2897 tmpcursor.par->IsWord(tmpcursor.pos-1) )
2900 SetCursor(tmpcursor.par, tmpcursor.pos);
2903 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
2906 void LyXText::SelectWord()
2908 /* Move cursor to the beginning, when not already there. */
2910 && !cursor.par->IsSeparator(cursor.pos-1)
2911 && !cursor.par->IsKomma(cursor.pos-1) )
2912 CursorLeftOneWord();
2914 /* set the sel cursor */
2915 sel_cursor = cursor;
2917 while ( cursor.pos < cursor.par->Last()
2918 && !cursor.par->IsSeparator(cursor.pos)
2919 && !cursor.par->IsKomma(cursor.pos) )
2921 SetCursor( cursor.par, cursor.pos );
2923 /* finally set the selection */
2928 /* -------> Select the word currently under the cursor when:
2929 1: no selection is currently set,
2930 2: the cursor is not at the borders of the word. */
2932 int LyXText::SelectWordWhenUnderCursor()
2934 if ( selection ) return 0;
2935 if ( cursor.pos < cursor.par->Last()
2936 && !cursor.par->IsSeparator(cursor.pos)
2937 && !cursor.par->IsKomma(cursor.pos)
2939 && !cursor.par->IsSeparator(cursor.pos -1)
2940 && !cursor.par->IsKomma(cursor.pos -1) ) {
2948 // This function is only used by the spellchecker for NextWord().
2949 // It doesn't handle LYX_ACCENTs and probably never will.
2950 char * LyXText::SelectNextWord(float & value)
2952 LyXParagraph * tmppar = cursor.par;
2954 // If this is not the very first word, skip rest of
2955 // current word because we are probably in the middle
2956 // of a word if there is text here.
2957 if (cursor.pos || cursor.par->previous) {
2958 while (cursor.pos < cursor.par->Last()
2959 && cursor.par->IsLetter(cursor.pos))
2962 // Now, skip until we have real text (will jump paragraphs)
2963 while ((cursor.par->Last() > cursor.pos
2964 && (!cursor.par->IsLetter(cursor.pos)
2965 || cursor.par->getFont(cursor.pos).latex() == LyXFont::ON))
2966 || (cursor.par->Last() == cursor.pos
2967 && cursor.par->Next())){
2968 if (cursor.pos == cursor.par->Last()) {
2969 cursor.par = cursor.par->Next();
2976 // Update the value if we changed paragraphs
2977 if (cursor.par != tmppar){
2978 SetCursor(cursor.par, cursor.pos);
2979 value = float(cursor.y)/float(height);
2982 /* Start the selection from here */
2983 sel_cursor = cursor;
2987 /* and find the end of the word
2988 (optional hyphens are part of a word) */
2989 while (cursor.pos < cursor.par->Last()
2990 && (cursor.par->IsLetter(cursor.pos))
2991 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET &&
2992 cursor.par->GetInset(cursor.pos) != 0 &&
2993 cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 &&
2997 // Finally, we copy the word to a string and return it
3000 if (sel_cursor.pos < cursor.pos) {
3001 str = new char [cursor.pos - sel_cursor.pos + 2];
3002 LyXParagraph::size_type i, j;
3003 for (i = sel_cursor.pos, j = 0; i < cursor.pos; ++i) {
3004 if (cursor.par->GetChar(i) != LyXParagraph::META_INSET)
3005 str[j++] = cursor.par->GetChar(i);
3013 // This one is also only for the spellchecker
3014 void LyXText::SelectSelectedWord()
3016 /* move cursor to the beginning */
3017 SetCursor(sel_cursor.par, sel_cursor.pos);
3019 /* set the sel cursor */
3020 sel_cursor = cursor;
3024 /* now find the end of the word */
3025 while (cursor.pos < cursor.par->Last()
3026 && (cursor.par->IsLetter(cursor.pos)
3027 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET &&
3028 cursor.par->GetInset(cursor.pos) != 0 &&
3029 cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 &&
3033 SetCursor(cursor.par, cursor.pos);
3035 /* finally set the selection */
3040 /* -------> Delete from cursor up to the end of the current or next word. */
3041 void LyXText::DeleteWordForward()
3043 LyXCursor tmpcursor = cursor;
3045 if (!cursor.par->Last())
3048 /* -------> Skip initial non-word stuff. */
3049 while ( cursor.pos < cursor.par->Last()
3050 && (cursor.par->IsSeparator(cursor.pos)
3051 || cursor.par->IsKomma(cursor.pos)) )
3054 SetCursorIntern(cursor.par, cursor.pos);
3055 selection = True; // to avoid deletion
3056 CursorRightOneWord();
3057 sel_cursor = cursor;
3061 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3067 /* -------> Delete from cursor to start of current or prior word. */
3068 void LyXText::DeleteWordBackward()
3070 LyXCursor tmpcursor = cursor;
3071 if (!cursor.par->Last())
3074 selection = true; // to avoid deletion
3075 CursorLeftOneWord();
3076 sel_cursor = cursor;
3084 /* -------> Kill to end of line. */
3085 void LyXText::DeleteLineForward()
3087 LyXCursor tmpcursor = cursor;
3088 if (!cursor.par->Last())
3092 sel_cursor = cursor;
3095 if (selection == false) {
3096 DeleteWordForward();
3104 // Change the case of a word at cursor position. The meaning of action
3106 // 0 change to lowercase
3107 // 1 capitalize word
3108 // 2 change to uppercase
3109 // This function directly manipulates LyXParagraph::text because there
3110 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3111 // that it is correct. I guess part of it should be moved to
3112 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3113 // it does not access outside of the allocated array as the older
3114 // version did. (JMarc)
3115 void LyXText::ChangeWordCase(LyXText::TextCase action)
3117 LyXParagraph * tmppar = cursor.par->ParFromPos(cursor.pos);
3119 SetUndo(Undo::FINISH, tmppar->previous, tmppar->next);
3121 LyXParagraph::size_type tmppos =
3122 cursor.par->PositionInParFromPos(cursor.pos);
3123 while (tmppos < tmppar->size()) {
3124 unsigned char c = tmppar->text[tmppos];
3125 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3127 if (c != LyXParagraph::META_INSET) {
3129 case text_lowercase:
3132 case text_capitalization:
3134 action = text_lowercase;
3136 case text_uppercase:
3142 tmppar->text[tmppos] = c;
3145 CheckParagraph(tmppar, tmppos);
3146 CursorRightOneWord();
3150 void LyXText::Delete()
3152 // this is a very easy implementation
3154 LyXCursor old_cursor = cursor;
3155 int old_cur_par_id = old_cursor.par->id();
3156 int old_cur_par_prev_id = old_cursor.par->previous ?
3157 old_cursor.par->previous->id() : 0;
3159 // just move to the right
3160 CursorRightIntern();
3162 // This check is not very good...
3163 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3164 // and that can very well delete the par or par->previous in
3165 // old_cursor. Will a solution where we compare paragraph id's
3168 if ((cursor.par->previous ? cursor.par->previous->id() : 0)
3169 == old_cur_par_prev_id
3170 && cursor.par->id() != old_cur_par_id)
3171 return; // delete-empty-paragraph-mechanism has done it
3173 if (cursor.par->previous == old_cursor.par->previous
3174 && cursor.par != old_cursor.par)
3175 return; // delete-empty-paragraph-mechanism has done it
3177 // if you had success make a backspace
3178 if (old_cursor.par != cursor.par || old_cursor.pos != cursor.pos) {
3179 LyXCursor tmpcursor = cursor;
3180 cursor = old_cursor; // to make sure undo gets the right cursor position
3181 SetUndo(Undo::DELETE,
3182 cursor.par->ParFromPos(cursor.pos)->previous,
3183 cursor.par->ParFromPos(cursor.pos)->next);
3190 void LyXText::Backspace()
3192 LyXParagraph * tmppar;
3193 Row * tmprow, * row;
3197 /* table stuff -- begin */
3198 if (cursor.par->table) {
3202 /* table stuff -- end */
3204 LyXFont rawtmpfont = current_font;
3205 LyXFont realtmpfont = real_current_font;
3207 // Get the font that is used to calculate the baselineskip
3208 int const lastpos = cursor.par->Last();
3209 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
3211 if (cursor.pos == 0) {
3212 // we may paste some paragraphs
3214 // is it an empty paragraph?
3217 || (lastpos == 1 && cursor.par->IsSeparator(0)))
3218 && !(cursor.par->Next()
3219 && cursor.par->footnoteflag ==
3220 LyXParagraph::NO_FOOTNOTE
3221 && cursor.par->Next()->footnoteflag ==
3222 LyXParagraph::OPEN_FOOTNOTE)) {
3224 if (cursor.par->previous) {
3225 tmppar = cursor.par->previous->FirstPhysicalPar();
3226 if (cursor.par->GetLayout() == tmppar->GetLayout()
3227 && cursor.par->footnoteflag == tmppar->footnoteflag
3228 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3230 tmppar->line_bottom = cursor.par->line_bottom;
3231 tmppar->added_space_bottom = cursor.par->added_space_bottom;
3232 tmppar->pagebreak_bottom = cursor.par->pagebreak_bottom;
3237 // the layout things can change the height of a row !
3238 tmpheight = cursor.row->height;
3239 SetHeightOfRow(cursor.row);
3240 if (cursor.row->height != tmpheight) {
3241 refresh_y = cursor.y - cursor.row->baseline;
3242 refresh_row = cursor.row;
3243 status = LyXText::NEED_MORE_REFRESH;
3248 if (cursor.par->ParFromPos(cursor.pos)->previous){
3249 SetUndo(Undo::DELETE,
3250 cursor.par->ParFromPos(cursor.pos)->previous->previous,
3251 cursor.par->ParFromPos(cursor.pos)->next);
3253 tmppar = cursor.par;
3254 tmprow = cursor.row;
3256 /* Pasting is not allowed, if the paragraphs have different
3257 layout. I think it is a real bug of all other
3258 word processors to allow it. It confuses the user.
3259 Even so with a footnote paragraph and a non-footnote
3260 paragraph. I will not allow pasting in this case,
3261 because the user would be confused if the footnote behaves
3262 different wether it is open or closed.
3264 Correction: Pasting is always allowed with standard-layout
3266 if (cursor.par != tmppar
3267 && (cursor.par->GetLayout() == tmppar->GetLayout()
3268 || !tmppar->GetLayout())
3269 && cursor.par->footnoteflag == tmppar->footnoteflag
3270 /* table stuff -- begin*/
3271 && !cursor.par->table /* no pasting of tables */
3272 /* table stuff -- end*/
3273 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3275 cursor.par->PasteParagraph();
3278 cursor.par->IsSeparator(cursor.pos - 1)))
3279 cursor.par->InsertChar(cursor.pos, ' ');
3284 status = LyXText::NEED_MORE_REFRESH;
3285 refresh_row = cursor.row;
3286 refresh_y = cursor.y - cursor.row->baseline;
3288 // remove the lost paragraph
3289 RemoveParagraph(tmprow);
3292 AppendParagraph(cursor.row);
3293 UpdateCounters(cursor.row);
3295 // the row may have changed, block, hfills etc.
3296 SetCursor(cursor.par, cursor.pos);
3299 /* this is the code for a normal backspace, not pasting
3301 SetUndo(Undo::DELETE,
3302 cursor.par->ParFromPos(cursor.pos)->previous,
3303 cursor.par->ParFromPos(cursor.pos)->next);
3306 // some insets are undeletable here
3307 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
3308 if (!cursor.par->GetInset(cursor.pos)->Deletable())
3310 // force complete redo when erasing display insets
3311 // this is a cruel mathod but save..... Matthias
3312 if (cursor.par->GetInset(cursor.pos)->display()){
3313 cursor.par->Erase(cursor.pos);
3320 y = cursor.y - row->baseline;
3321 LyXParagraph::size_type z;
3322 /* remember that a space at the end of a row doesnt count
3323 * when calculating the fill */
3324 if (cursor.pos < RowLast(row) ||
3325 !cursor.par->IsLineSeparator(cursor.pos)) {
3326 row->fill += SingleWidth(cursor.par, cursor.pos);
3329 /* some special code when deleting a newline. This is similar
3330 * to the behavior when pasting paragraphs */
3331 if (cursor.pos && cursor.par->IsNewline(cursor.pos)) {
3332 cursor.par->Erase(cursor.pos);
3333 // refresh the positions
3335 while (tmprow->next && tmprow->next->par == row->par) {
3336 tmprow = tmprow->next;
3339 if (cursor.par->IsLineSeparator(cursor.pos - 1))
3342 if (cursor.pos < cursor.par->Last() && !cursor.par->IsSeparator(cursor.pos)) {
3343 cursor.par->InsertChar(cursor.pos, ' ');
3344 // refresh the positions
3346 while (tmprow->next && tmprow->next->par == row->par) {
3347 tmprow = tmprow->next;
3352 cursor.par->Erase(cursor.pos);
3354 // refresh the positions
3356 while (tmprow->next && tmprow->next->par == row->par) {
3357 tmprow = tmprow->next;
3361 #ifndef FIX_DOUBLE_SPACE
3362 // delete superfluous blanks
3363 if (cursor.pos < cursor.par->Last() - 1 &&
3364 (cursor.par->IsLineSeparator(cursor.pos))) {
3366 if (cursor.pos == BeginningOfMainBody(cursor.par)
3368 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
3369 cursor.par->Erase(cursor.pos);
3370 // refresh the positions
3372 while (tmprow->next &&
3373 tmprow->next->par == row->par) {
3374 tmprow = tmprow->next;
3377 if (cursor.pos) // move one character left
3383 // delete newlines at the beginning of paragraphs
3384 while (cursor.par->Last() &&
3385 cursor.par->IsNewline(cursor.pos) &&
3386 cursor.pos == BeginningOfMainBody(cursor.par)) {
3387 cursor.par->Erase(cursor.pos);
3388 // refresh the positions
3390 while (tmprow->next &&
3391 tmprow->next->par == row->par) {
3392 tmprow = tmprow->next;
3398 // is there a break one row above
3399 if (row->previous && row->previous->par == row->par) {
3400 z = NextBreakPoint(row->previous, paperwidth);
3401 if ( z >= row->pos) {
3404 tmprow = row->previous;
3406 // maybe the current row is now empty
3407 if (row->pos >= row->par->Last()) {
3412 BreakAgainOneRow(row);
3413 if (row->next && row->next->par == row->par)
3414 need_break_row = row->next;
3419 // set the dimensions of the row above
3420 y -= tmprow->height;
3421 tmprow->fill = Fill(tmprow, paperwidth);
3422 SetHeightOfRow(tmprow);
3425 refresh_row = tmprow;
3426 status = LyXText::NEED_MORE_REFRESH;
3427 current_font = rawtmpfont;
3428 real_current_font = realtmpfont;
3429 SetCursor(cursor.par, cursor.pos, false);
3430 // check, whether the last character's font has changed.
3431 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3432 if (rawparfont != rawtmpfont)
3433 RedoHeightOfParagraph(cursor);
3438 // break the cursor row again
3439 z = NextBreakPoint(row, paperwidth);
3441 if (z != RowLast(row) ||
3442 (row->next && row->next->par == row->par &&
3443 RowLast(row) == row->par->Last() - 1)){
3445 /* it can happen that a paragraph loses one row
3446 * without a real breakup. This is when a word
3447 * is to long to be broken. Well, I don t care this
3449 if (row->next && row->next->par == row->par &&
3450 RowLast(row) == row->par->Last() - 1)
3451 RemoveRow(row->next);
3455 status = LyXText::NEED_MORE_REFRESH;
3457 BreakAgainOneRow(row);
3458 current_font = rawtmpfont;
3459 real_current_font = realtmpfont;
3460 SetCursor(cursor.par, cursor.pos, false);
3461 // cursor MUST be in row now
3463 if (row->next && row->next->par == row->par)
3464 need_break_row = row->next;
3468 // set the dimensions of the row
3469 row->fill = Fill(row, paperwidth);
3470 int tmpheight = row->height;
3471 SetHeightOfRow(row);
3472 if (tmpheight == row->height)
3473 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3475 status = LyXText::NEED_MORE_REFRESH;
3478 current_font = rawtmpfont;
3479 real_current_font = realtmpfont;
3480 SetCursor(cursor.par, cursor.pos, false);
3484 // restore the current font
3485 // That is what a user expects!
3486 current_font = rawtmpfont;
3487 real_current_font = realtmpfont;
3489 // check, wether the last characters font has changed.
3490 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3491 if (rawparfont != rawtmpfont) {
3492 RedoHeightOfParagraph(cursor);
3494 // now the special right address boxes
3495 if (textclasslist.Style(parameters->textclass,
3496 cursor.par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3497 RedoDrawingOfParagraph(cursor);
3503 void LyXText::GetVisibleRow(LyXScreen & scr, int offset,
3504 Row * row_ptr, long y)
3506 /* returns a printed row */
3507 LyXDirection direction = row_ptr->par->getParDirection();
3508 LyXParagraph::size_type vpos, pos, pos_end;
3510 int y_top, y_bottom;
3511 float fill_separator, fill_hfill, fill_label_hfill;
3512 LyXParagraph * par, * firstpar;
3515 if (row_ptr->height <= 0) {
3516 lyxerr << "LYX_ERROR: row.height: " << row_ptr->height << endl;
3519 PrepareToPrint(row_ptr, x, fill_separator,
3520 fill_hfill, fill_label_hfill);
3522 /* initialize the pixmap */
3524 scr.fillRectangle(gc_clear,
3525 0, offset, paperwidth, row_ptr->height);
3526 // check for NOT FAST SELECTION
3527 if (!fast_selection && !mono_video && selection) {
3528 /* selection code */
3529 if (sel_start_cursor.row == row_ptr &&
3530 sel_end_cursor.row == row_ptr) {
3531 if (sel_start_cursor.x < sel_end_cursor.x)
3532 scr.fillRectangle(gc_selection, sel_start_cursor.x,
3534 sel_end_cursor.x - sel_start_cursor.x,
3537 scr.fillRectangle(gc_selection, sel_end_cursor.x,
3539 sel_start_cursor.x - sel_end_cursor.x,
3542 else if (sel_start_cursor.row == row_ptr) {
3543 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3544 scr.fillRectangle(gc_selection, sel_start_cursor.x,
3546 paperwidth - sel_start_cursor.x,
3549 scr.fillRectangle(gc_selection, 0, offset,
3550 sel_start_cursor.x, row_ptr->height);
3551 } else if (sel_end_cursor.row == row_ptr) {
3552 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3553 scr.fillRectangle(gc_selection, 0, offset,
3554 sel_end_cursor.x, row_ptr->height);
3556 scr.fillRectangle(gc_selection, sel_end_cursor.x,
3558 paperwidth - sel_end_cursor.x,
3560 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
3561 scr.fillRectangle(gc_selection, 0, offset,
3562 paperwidth, row_ptr->height);
3565 } // end of NOT FAST SELECTION code
3567 if (row_ptr->par->appendix){
3568 scr.drawVerticalLine(gc_math, 1, offset, offset+row_ptr->height);
3569 scr.drawVerticalLine(gc_math, paperwidth-2 , offset, offset+row_ptr->height);
3572 if (row_ptr->par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
3573 /* draw a marker at the left margin! */
3574 LyXFont font = GetFont(row_ptr->par, 0);
3575 int asc = font.maxAscent();
3576 int x = (LYX_PAPER_MARGIN - font.width('|')) / 2;
3577 int y1 = (offset + row_ptr->baseline);
3578 int y2 = (offset + row_ptr->baseline) - asc;
3580 scr.drawVerticalLine(gc_minipage, x, y1, y2);
3582 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3583 LyXFont font(LyXFont::ALL_SANE);
3584 font.setSize(LyXFont::SIZE_FOOTNOTE);
3585 font.setColor(LyXFont::RED);
3587 int box_x = LYX_PAPER_MARGIN;
3588 box_x += font.textWidth(" wide-tab ", 10);
3589 if (row_ptr->previous &&
3590 row_ptr->previous->par->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3592 switch (row_ptr->par->footnotekind) {
3593 case LyXParagraph::MARGIN:
3596 case LyXParagraph::FIG:
3599 case LyXParagraph::TAB:
3602 case LyXParagraph::WIDE_FIG:
3605 case LyXParagraph::WIDE_TAB:
3608 case LyXParagraph::ALGORITHM:
3611 case LyXParagraph::FOOTNOTE:
3616 // Determine background color.
3617 gc_type back = gc_lighted;
3621 scr.fillRectangle(back, LYX_PAPER_MARGIN, offset+1,
3622 box_x - LYX_PAPER_MARGIN,
3623 int(font.maxAscent())+
3624 int(font.maxDescent()));
3626 scr.drawLine(gc_foot,
3629 paperwidth - 2*LYX_PAPER_MARGIN);
3631 scr.drawString(font, fs,
3632 offset + int(font.maxAscent())+1,
3634 scr.drawVerticalLine(gc_foot,
3638 + int(font.maxAscent())+
3639 int(font.maxDescent()));
3641 scr.drawLine(gc_foot,
3643 + int(font.maxAscent())
3644 + int(font.maxDescent()) + 1,
3645 LYX_PAPER_MARGIN, box_x - LYX_PAPER_MARGIN);
3648 /* draw the open floats in a red box */
3649 scr.drawVerticalLine(gc_foot,
3651 offset, offset + row_ptr->height);
3653 scr.drawVerticalLine(gc_foot,
3654 paperwidth - LYX_PAPER_MARGIN,
3656 offset + row_ptr->height);
3659 if (row_ptr->previous &&
3660 row_ptr->previous->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3661 LyXFont font(LyXFont::ALL_SANE);
3662 font.setSize(LyXFont::SIZE_FOOTNOTE);
3664 int box_x = LYX_PAPER_MARGIN;
3665 box_x += font.textWidth(" wide-tab ", 10);
3667 scr.drawLine(gc_foot,
3670 paperwidth - LYX_PAPER_MARGIN - box_x);
3674 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
3675 row_ptr->par->GetLayout());
3676 firstpar = row_ptr->par->FirstPhysicalPar();
3679 y_bottom = row_ptr->height;
3681 /* is it a first row? */
3682 if (row_ptr->pos == 0
3683 && row_ptr->par == firstpar) {
3685 /* start of appendix? */
3686 if (row_ptr->par->start_of_appendix){
3687 scr.drawLine(gc_math,
3692 /* think about the margins */
3693 if (!row_ptr->previous)
3694 y_top += LYX_PAPER_MARGIN;
3696 if (row_ptr->par->pagebreak_top){ /* draw a top pagebreak */
3697 scr.drawOnOffLine(offset + y_top + 2 * DefaultHeight(),
3699 y_top += 3 * DefaultHeight();
3702 if (row_ptr->par->added_space_top.kind() == VSpace::VFILL) {
3703 /* draw a vfill top */
3704 scr.drawLine(gc_fill,
3706 0, LYX_PAPER_MARGIN);
3707 scr.drawLine(gc_fill,
3708 offset + y_top + 3 * DefaultHeight(),
3709 0, LYX_PAPER_MARGIN);
3710 scr.drawVerticalOnOffLine(LYX_PAPER_MARGIN / 2,
3712 offset + y_top + 3 *
3715 y_top += 3 * DefaultHeight();
3718 /* think about user added space */
3719 y_top += int(row_ptr->par->added_space_top.inPixels());
3721 /* think about the parskip */
3722 /* some parskips VERY EASY IMPLEMENTATION */
3723 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
3724 if (layout.latextype == LATEX_PARAGRAPH
3725 && firstpar->GetDepth() == 0
3726 && firstpar->Previous())
3727 y_top += parameters->getDefSkip().inPixels();
3728 else if (firstpar->Previous()
3729 && textclasslist.Style(parameters->textclass,
3730 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
3731 && firstpar->Previous()->GetDepth() == 0)
3732 // is it right to use defskip here, too? (AS)
3733 y_top += parameters->getDefSkip().inPixels();
3736 if (row_ptr->par->line_top) { /* draw a top line */
3737 y_top += GetFont(row_ptr->par, 0).ascent('x');
3739 scr.drawThickLine(offset + y_top,
3741 y_top += GetFont(row_ptr->par, 0).ascent('x');
3744 /* should we print a label? */
3745 if (layout.labeltype >= LABEL_STATIC
3746 && (layout.labeltype != LABEL_STATIC
3747 || layout.latextype != LATEX_ENVIRONMENT
3748 || row_ptr->par->IsFirstInSequence())) {
3749 font = GetFont(row_ptr->par, -2);
3750 if (!row_ptr->par->GetLabestring().empty()) {
3752 string tmpstring = row_ptr->par->GetLabestring();
3754 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
3755 if (parameters->secnumdepth >= 0){
3756 /* this is special code for the chapter layout. This is printed in
3757 * an extra row and has a pagebreak at the top. */
3758 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue())
3759 + int(layout.parsep) * DefaultHeight();
3760 if (direction == LYX_DIR_RIGHT_TO_LEFT)
3761 tmpx = paperwidth - LeftMargin(row_ptr) -
3762 font.stringWidth(tmpstring);
3763 scr.drawString(font, tmpstring,
3764 offset + row_ptr->baseline
3765 - row_ptr->ascent_of_text - maxdesc,
3769 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3770 tmpx = x - font.stringWidth(layout.labelsep)
3771 - font.stringWidth(tmpstring);
3773 tmpx = paperwidth - LeftMargin(row_ptr)
3774 + font.stringWidth(layout.labelsep);
3775 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3776 LyXFont font(LyXFont::ALL_SANE);
3777 font.setSize(LyXFont::SIZE_SMALL);
3778 tmpx += font.textWidth("Mwide-figM", 10);
3782 scr.drawString(font, tmpstring,
3783 offset + row_ptr->baseline, int(tmpx));
3786 /* the labels at the top of an environment. More or less for bibliography */
3787 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
3788 layout.labeltype == LABEL_BIBLIO ||
3789 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
3790 if (row_ptr->par->IsFirstInSequence()) {
3791 font = GetFont(row_ptr->par, -2);
3792 if (!row_ptr->par->GetLabestring().empty()) {
3793 string tmpstring = row_ptr->par->GetLabestring();
3795 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue()
3796 + (layout.labelbottomsep * DefaultHeight()));
3799 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
3800 tmpx = ( ((direction == LYX_DIR_LEFT_TO_RIGHT)
3801 ? x : LeftMargin(row_ptr) )
3802 + paperwidth - RightMargin(row_ptr) ) / 2;
3803 tmpx -= (font.stringWidth(tmpstring)/2);
3804 } else if (direction == LYX_DIR_RIGHT_TO_LEFT)
3805 tmpx = paperwidth - LeftMargin(row_ptr) -
3806 font.stringWidth(tmpstring);
3808 scr.drawString(font, tmpstring,
3809 offset + row_ptr->baseline
3810 - row_ptr->ascent_of_text - maxdesc,
3815 if (layout.labeltype == LABEL_BIBLIO) { // ale970302
3816 if (row_ptr->par->bibkey) {
3817 font = GetFont(row_ptr->par, -1);
3818 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3819 tmpx = x - font.stringWidth(layout.labelsep)
3820 - row_ptr->par->bibkey->Width(font);
3822 tmpx = paperwidth - LeftMargin(row_ptr)
3823 + font.stringWidth(layout.labelsep);
3824 row_ptr->par->bibkey->Draw(font, scr,
3825 offset + row_ptr->baseline,
3831 /* is it a last row? */
3832 par = row_ptr->par->LastPhysicalPar();
3833 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
3834 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
3836 /* think about the margins */
3838 y_bottom -= LYX_PAPER_MARGIN;
3840 /* draw a bottom pagebreak */
3841 if (firstpar->pagebreak_bottom) {
3842 scr.drawOnOffLine(offset + y_bottom - 2 *
3845 y_bottom -= 3 * DefaultHeight();
3848 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
3849 /* draw a vfill bottom */
3850 scr.drawLine(gc_fill,
3851 offset + y_bottom - 3 * DefaultHeight(),
3852 0, LYX_PAPER_MARGIN);
3853 scr.drawLine(gc_fill, offset + y_bottom - 2,
3854 0, LYX_PAPER_MARGIN);
3855 scr.drawVerticalOnOffLine(LYX_PAPER_MARGIN / 2,
3856 offset + y_bottom - 3 * DefaultHeight(),
3857 offset + y_bottom - 2
3859 y_bottom -= 3* DefaultHeight();
3862 /* think about user added space */
3863 y_bottom -= int(firstpar->added_space_bottom.inPixels());
3865 if (firstpar->line_bottom) {
3866 /* draw a bottom line */
3867 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3869 scr.drawThickLine(offset + y_bottom,
3871 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3875 /* draw the text in the pixmap */
3876 pos_end = RowLast(row_ptr);
3878 vpos = row_ptr->pos;
3879 /* table stuff -- begin*/
3880 if (row_ptr->par->table) {
3882 int cell = NumberOfCell(row_ptr->par, row_ptr->pos);
3884 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3886 while (vpos <= pos_end) {
3887 pos = vis2log(vpos);
3888 if (row_ptr->par->IsNewline(pos)) {
3890 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
3891 /* draw the table lines, still very simple */
3892 on_off = !row_ptr->par->table->TopLine(cell);
3894 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
3895 !row_ptr->par->table->IsContRow(cell))
3896 scr.drawTableLine(offset + row_ptr->baseline -
3897 row_ptr->ascent_of_text,
3898 int(x_old), int(x - x_old), on_off);
3899 on_off = !row_ptr->par->table->BottomLine(cell);
3900 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
3901 row_ptr->par->table->VeryLastRow(cell))
3902 scr.drawTableLine(offset + y_bottom - 1,
3903 int(x_old), int(x - x_old), on_off);
3904 on_off = !row_ptr->par->table->LeftLine(cell);
3906 scr.drawVerticalTableLine(int(x_old),
3907 offset + row_ptr->baseline -
3908 row_ptr->ascent_of_text,
3909 offset + y_bottom - 1,
3911 on_off = !row_ptr->par->table->RightLine(cell);
3913 scr.drawVerticalTableLine(int(x) -
3914 row_ptr->par->table->AdditionalWidth(cell),
3915 offset + row_ptr->baseline -
3916 row_ptr->ascent_of_text,
3917 offset + y_bottom - 1,
3920 /* take care about the alignment and other spaces */
3922 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3923 if (row_ptr->par->table->IsFirstCell(cell))
3924 --cell; // little hack, sorry
3926 } else if (row_ptr->par->IsHfill(pos)) {
3929 scr.drawVerticalLine(gc_fill, int(x),
3930 offset + row_ptr->baseline - DefaultHeight()/2,
3931 offset + row_ptr->baseline);
3935 if (row_ptr->par->IsSeparator(pos)) {
3937 x+= SingleWidth(row_ptr->par, pos);
3938 /* -------> Only draw protected spaces when not in
3939 * free-spacing mode. */
3940 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
3941 scr.drawVerticalLine(gc_fill, int(tmpx),
3942 offset + row_ptr->baseline - 3,
3943 offset + row_ptr->baseline - 1);
3944 scr.drawLine(gc_fill,
3945 offset + row_ptr->baseline - 1,
3948 scr.drawVerticalLine(gc_fill, int(x-2),
3949 offset + row_ptr->baseline - 3,
3950 offset + row_ptr->baseline - 1);
3951 /* what about underbars? */
3952 font = GetFont(row_ptr->par, pos);
3953 if (font.underbar() == LyXFont::ON
3954 && font.latex() != LyXFont::ON) {
3955 scr.drawLine(gc_copy,
3957 row_ptr->baseline + 2,
3964 Draw(row_ptr, vpos, scr, offset, x);
3968 /* do not forget the very last cell. This has no NEWLINE so
3969 * ignored by the code above*/
3970 if (cell == row_ptr->par->table->GetNumberOfCells()-1){
3971 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
3972 on_off = !row_ptr->par->table->TopLine(cell);
3974 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
3975 !row_ptr->par->table->IsContRow(cell))
3977 scr.drawTableLine(offset + row_ptr->baseline -
3978 row_ptr->ascent_of_text,
3979 int(x_old), int(x - x_old), on_off);
3980 on_off = !row_ptr->par->table->BottomLine(cell);
3981 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
3982 row_ptr->par->table->VeryLastRow(cell))
3984 scr.drawTableLine(offset + y_bottom - 1,
3985 int(x_old), int(x - x_old), on_off);
3986 on_off = !row_ptr->par->table->LeftLine(cell);
3988 scr.drawVerticalTableLine(int(x_old),
3989 offset + row_ptr->baseline -
3990 row_ptr->ascent_of_text,
3991 offset + y_bottom - 1,
3993 on_off = !row_ptr->par->table->RightLine(cell);
3995 scr.drawVerticalTableLine(int(x) -
3996 row_ptr->par->table->AdditionalWidth(cell),
3997 offset + row_ptr->baseline -
3998 row_ptr->ascent_of_text,
3999 offset + y_bottom - 1,
4003 /* table stuff -- end*/
4004 LyXParagraph::size_type main_body =
4005 BeginningOfMainBody(row_ptr->par);
4006 if (main_body > 0 &&
4007 (main_body-1 > pos_end ||
4008 !row_ptr->par->IsLineSeparator(main_body-1)))
4011 while (vpos <= pos_end) {
4012 pos = vis2log(vpos);
4013 if (main_body > 0 && pos == main_body-1) {
4014 x += fill_label_hfill
4015 + GetFont(row_ptr->par, -2).stringWidth(layout.labelsep)
4016 - SingleWidth(row_ptr->par, main_body-1);
4019 if (row_ptr->par->IsHfill(pos)) {
4021 scr.drawVerticalLine(gc_fill, int(x),
4022 offset + row_ptr->baseline - DefaultHeight()/2,
4023 offset + row_ptr->baseline);
4024 if (HfillExpansion(row_ptr, pos)) {
4025 if (pos >= main_body) {
4026 scr.drawOnOffLine(offset + row_ptr->baseline -
4032 scr.drawOnOffLine(offset + row_ptr->baseline -
4035 int(fill_label_hfill));
4036 x += fill_label_hfill;
4038 scr.drawVerticalLine(gc_fill, int(x),
4039 offset + row_ptr->baseline -
4041 offset + row_ptr->baseline);
4046 if (row_ptr->par->IsSeparator(pos)) {
4048 x+= SingleWidth(row_ptr->par, pos);
4049 if (pos >= main_body)
4051 /* -------> Only draw protected spaces when not in
4052 * free-spacing mode. */
4053 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
4055 scr.drawVerticalLine(gc_fill, int(tmpx),
4056 offset + row_ptr->baseline - 3,
4057 offset + row_ptr->baseline - 1);
4058 scr.drawLine(gc_fill,
4059 offset + row_ptr->baseline - 1,
4062 scr.drawVerticalLine(gc_fill, int(x-2),
4063 offset + row_ptr->baseline - 3,
4064 offset + row_ptr->baseline - 1);
4065 /* what about underbars? */
4066 font = GetFont(row_ptr->par, pos);
4067 if (font.underbar() == LyXFont::ON
4068 && font.latex() != LyXFont::ON) {
4069 scr.drawLine(gc_copy,
4070 offset + row_ptr->baseline + 2,
4077 Draw(row_ptr, vpos, scr, offset, x);
4081 // check for FAST SELECTION
4082 if (fast_selection || mono_video) {
4085 /* selection code */
4086 if (sel_start_cursor.row == row_ptr && sel_end_cursor.row == row_ptr) {
4087 scr.fillRectangle(gc_select, sel_start_cursor.x, offset,
4088 sel_end_cursor.x - sel_start_cursor.x,
4090 } else if (sel_start_cursor.row == row_ptr) {
4091 scr.fillRectangle(gc_select, sel_start_cursor.x, offset,
4092 paperwidth - sel_start_cursor.x,
4094 } else if (sel_end_cursor.row == row_ptr) {
4095 scr.fillRectangle(gc_select, 0, offset,
4098 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
4099 scr.fillRectangle(gc_select, 0, offset,
4100 paperwidth, row_ptr->height);
4105 // end of FAST SELECTION code
4110 int LyXText::DefaultHeight() const
4112 LyXFont font(LyXFont::ALL_SANE);
4113 return int(font.maxAscent() + font.maxDescent() * 1.5);
4117 /* returns the column near the specified x-coordinate of the row
4118 * x is set to the real beginning of this column */
4119 int LyXText::GetColumnNearX(Row * row, int & x) const
4122 float fill_separator, fill_hfill, fill_label_hfill;
4124 PrepareToPrint(row, tmpx, fill_separator,
4125 fill_hfill, fill_label_hfill);
4127 LyXDirection direction = row->par->getParDirection();
4128 LyXParagraph::size_type vc = row->pos;
4129 LyXParagraph::size_type last = RowLast(row);
4130 LyXParagraph::size_type c;
4132 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
4133 row->par->GetLayout());
4134 /* table stuff -- begin */
4135 if (row->par->table) {
4136 if (row->next && row->next->par == row->par //the last row doesn't need a newline at the end
4137 && row->par->IsNewline(last))
4139 int cell = NumberOfCell(row->par, row->pos);
4142 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4144 && (c = vis2log(vc)) >= 0
4145 && tmpx + (SingleWidth(row->par, c)/2) <= x
4147 if (row->par->IsNewline(c)) {
4148 if (x_old + row->par->table->WidthOfColumn(cell) <= x){
4149 tmpx = x_old + row->par->table->WidthOfColumn(cell);
4152 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4157 tmpx += SingleWidth(row->par, c);
4162 /* table stuff -- end*/
4163 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
4164 float last_tmpx = tmpx;
4166 if (main_body > 0 &&
4167 (main_body-1 > last ||
4168 !row->par->IsLineSeparator(main_body-1)))
4171 while (vc <= last && tmpx <= x) {
4174 if (main_body > 0 && c == main_body-1) {
4175 tmpx += fill_label_hfill +
4176 GetFont(row->par, -2).stringWidth(layout.labelsep);
4177 if (row->par->IsLineSeparator(main_body-1))
4178 tmpx -= SingleWidth(row->par, main_body-1);
4181 tmpx += SingleWidth(row->par, c);
4182 if (HfillExpansion(row, c)) {
4186 tmpx += fill_label_hfill;
4188 else if (c >= main_body
4189 && row->par->IsSeparator(c)) {
4190 tmpx+= fill_separator;
4195 if (vc > row->pos && (tmpx+last_tmpx)/2 > x) {
4200 /* make sure that a last space in a row doesnt count */
4201 if (row->pos <= last
4202 && !(!row->next || row->next->par != row->par))
4203 if (direction == LYX_DIR_LEFT_TO_RIGHT && vc > last
4204 && row->par->IsLineSeparator(vis2log(last)) ) {
4206 tmpx -= fill_separator+SingleWidth(row->par, vis2log(last));
4207 } else if (direction == LYX_DIR_RIGHT_TO_LEFT
4209 && row->par->IsLineSeparator(vis2log(row->pos)) ) {
4211 tmpx += fill_separator+SingleWidth(row->par, vis2log(row->pos));
4214 if (row->pos > last) // Row is empty?
4216 else if (vc <= last) {
4218 LyXDirection direction = row->par->getLetterDirection(c);
4219 if (vc > row->pos && row->par->IsLineSeparator(c)
4220 && row->par->getLetterDirection(vis2log(vc - 1)) != direction)
4222 if (direction == LYX_DIR_RIGHT_TO_LEFT)
4225 c = vis2log(last)+1;
4226 if (row->par->getLetterDirection(c - 1) == LYX_DIR_RIGHT_TO_LEFT)
4230 if (!row->par->table && row->pos <= last && c > last
4231 && row->par->IsNewline(last)) {
4232 if (row->par->getLetterDirection(last) == LYX_DIR_LEFT_TO_RIGHT)
4233 tmpx -= SingleWidth(row->par, last);
4235 tmpx += SingleWidth(row->par, last);
4245 /* turn the selection into a new environment. If there is no selection,
4246 * create an empty environment */
4247 void LyXText::InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind)
4249 /* no footnoteenvironment in a footnoteenvironment */
4250 if (cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4251 WriteAlert(_("Impossible operation"),
4252 _("You can't insert a float in a float!"),
4256 /* no marginpars in minipages */
4257 if (kind == LyXParagraph::MARGIN
4258 && cursor.par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4259 WriteAlert(_("Impossible operation"),
4260 _("You can't insert a marginpar in a minipage!"),
4265 /* this doesnt make sense, if there is no selection */
4266 bool dummy_selection = false;
4268 sel_start_cursor = cursor; /* dummy selection */
4269 sel_end_cursor = cursor;
4270 dummy_selection = true;
4273 LyXParagraph *tmppar;
4275 if (sel_start_cursor.par->table || sel_end_cursor.par->table){
4276 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
4280 /* a test to make sure there is not already a footnote
4281 * in the selection. */
4283 tmppar = sel_start_cursor.par->ParFromPos(sel_start_cursor.pos);
4285 while (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos) &&
4286 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
4287 tmppar = tmppar->next;
4289 if (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)
4290 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4291 WriteAlert(_("Impossible operation"),
4292 _("Float would include float!"),
4297 /* ok we have a selection. This is always between sel_start_cursor
4298 * and sel_end cursor */
4300 SetUndo(Undo::FINISH,
4301 sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous,
4302 sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)->next);
4304 if (sel_end_cursor.pos > 0
4305 && sel_end_cursor.par->IsLineSeparator(sel_end_cursor.pos - 1))
4306 sel_end_cursor.pos--; /* please break before a space at
4308 if (sel_start_cursor.par == sel_end_cursor.par
4309 && sel_start_cursor.pos > sel_end_cursor.pos)
4310 sel_start_cursor.pos--;
4312 sel_end_cursor.par->BreakParagraphConservative(sel_end_cursor.pos);
4314 sel_end_cursor.par = sel_end_cursor.par->Next();
4315 sel_end_cursor.pos = 0;
4317 // don't forget to insert a dummy layout paragraph if necessary
4318 if (sel_start_cursor.par->GetLayout() != sel_end_cursor.par->layout){
4319 sel_end_cursor.par->BreakParagraphConservative(0);
4320 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4321 sel_end_cursor.par = sel_end_cursor.par->next;
4324 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4326 cursor = sel_end_cursor;
4328 /* please break behind a space, if there is one. The space should
4330 if (sel_start_cursor.pos > 0
4331 && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1))
4332 sel_start_cursor.pos--;
4333 if (sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) {
4334 sel_start_cursor.par->Erase(sel_start_cursor.pos);
4337 sel_start_cursor.par->BreakParagraphConservative(sel_start_cursor.pos);
4338 tmppar = sel_start_cursor.par->Next();
4340 if (dummy_selection) {
4342 if (kind == LyXParagraph::TAB
4343 || kind == LyXParagraph::FIG
4344 || kind == LyXParagraph::WIDE_TAB
4345 || kind == LyXParagraph::WIDE_FIG
4346 || kind == LyXParagraph::ALGORITHM) {
4347 int lay = textclasslist.NumberOfLayout(parameters->textclass,
4349 if (lay == -1) // layout not found
4350 // use default layout "Standard" (0)
4352 tmppar->SetLayout(lay);
4356 if (sel_start_cursor.pos > 0) {
4357 /* the footnote-environment should begin with a standard layout.
4358 * Imagine you insert a footnote within an enumeration, you
4359 * certainly do not want an enumerated footnote! */
4363 /* this is a exception the user would sometimes expect, I hope */
4364 sel_start_cursor.par->Clear();
4368 while (tmppar != sel_end_cursor.par) {
4369 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4370 tmppar->footnotekind = kind;
4371 tmppar = tmppar->Next();
4374 RedoParagraphs(sel_start_cursor, sel_end_cursor.par->Next());
4376 SetCursor(sel_start_cursor.par->Next(), 0);
4382 // returns pointer to a specified row
4383 Row * LyXText::GetRow(LyXParagraph * par,
4384 LyXParagraph::size_type pos, long & y) const
4389 if (par == currentrow->par || par == currentrow->par->Previous()) {
4390 // do not dereference par, it may have been deleted
4391 // already! (Matthias)
4392 while (currentrow->previous && currentrow->previous->par != par) {
4393 currentrow = currentrow->previous;
4394 currentrow_y -= currentrow->height;
4396 while (currentrow->previous && currentrow->previous->par == par) {
4397 currentrow = currentrow->previous;
4398 currentrow_y -= currentrow->height;
4401 tmprow = currentrow;
4403 // find the first row of the specified paragraph
4404 while (tmprow->next && (tmprow->par != par)) {
4405 y += tmprow->height;
4406 tmprow = tmprow->next;
4409 if (tmprow->par == par){
4410 // now find the wanted row
4411 while (tmprow->pos < pos && tmprow->next && tmprow->next->par == par &&
4412 tmprow->next->pos <= pos) {
4413 y += tmprow->height;
4414 tmprow = tmprow->next;
4416 currentrow = tmprow;
4423 // find the first row of the specified paragraph
4424 while (tmprow->next && (tmprow->par != par)) {
4425 y += tmprow->height;
4426 tmprow = tmprow->next;
4429 // now find the wanted row
4430 while (tmprow->pos < pos && tmprow->next && tmprow->next->par == par &&
4431 tmprow->next->pos <= pos) {
4432 y += tmprow->height;
4433 tmprow = tmprow->next;
4436 currentrow = tmprow;