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"
25 #include "bufferparams.h"
27 #include "lyxscreen.h"
28 #include "minibuffer.h"
41 static const int LYX_PAPER_MARGIN = 20;
44 extern int mono_video;
45 extern int reverse_video;
46 extern int fast_selection;
49 extern BufferView * current_view;
54 extern int bibitemMaxWidth(Painter &, LyXFont const &);
56 extern int bibitemMaxWidth(LyXFont const &);
59 #define FIX_DOUBLE_SPACE 1
61 int LyXText::SingleWidth(LyXParagraph * par,
62 LyXParagraph::size_type pos) const
64 char c = par->GetChar(pos);
65 return SingleWidth(par, pos, c);
70 int LyXText::SingleWidth(LyXParagraph * par,
71 LyXParagraph::size_type pos, char c) const
73 LyXFont font = GetFont(par, pos);
75 // The most common case is handled first (Asger)
79 } else if (IsHfillChar(c)) {
80 return 3; /* Because of the representation
81 * as vertical lines */
82 } else if (c == LyXParagraph::META_FOOTNOTE ||
83 c == LyXParagraph::META_MARGIN ||
84 c == LyXParagraph::META_FIG ||
85 c == LyXParagraph::META_TAB ||
86 c == LyXParagraph::META_WIDE_FIG ||
87 c == LyXParagraph::META_WIDE_TAB ||
88 c == LyXParagraph::META_ALGORITHM) {
91 case LyXParagraph::META_MARGIN:
94 case LyXParagraph::META_FIG:
97 case LyXParagraph::META_TAB:
100 case LyXParagraph::META_ALGORITHM:
103 case LyXParagraph::META_WIDE_FIG:
106 case LyXParagraph::META_WIDE_TAB:
109 case LyXParagraph::META_FOOTNOTE:
115 return font.stringWidth(fs);
116 } else if (c == LyXParagraph::META_INSET) {
117 Inset * tmpinset= par->GetInset(pos);
119 return par->GetInset(pos)->width(owner_->painter(),
124 } else if (IsSeparatorChar(c))
126 else if (IsNewlineChar(c))
128 return font.width(c);
131 int LyXText::SingleWidth(LyXParagraph * par,
132 LyXParagraph::size_type pos, char c) const
134 LyXFont font = GetFont(par, pos);
136 // The most common case is handled first (Asger)
137 if (IsPrintable(c)) {
138 return font.width(c);
140 } else if (IsHfillChar(c)) {
141 return 3; /* Because of the representation
142 * as vertical lines */
144 } else if (c == LyXParagraph::META_FOOTNOTE ||
145 c == LyXParagraph::META_MARGIN ||
146 c == LyXParagraph::META_FIG ||
147 c == LyXParagraph::META_TAB ||
148 c == LyXParagraph::META_WIDE_FIG ||
149 c == LyXParagraph::META_WIDE_TAB ||
150 c == LyXParagraph::META_ALGORITHM)
154 case LyXParagraph::META_MARGIN:
157 case LyXParagraph::META_FIG:
160 case LyXParagraph::META_TAB:
163 case LyXParagraph::META_ALGORITHM:
166 case LyXParagraph::META_WIDE_FIG:
169 case LyXParagraph::META_WIDE_TAB:
172 case LyXParagraph::META_FOOTNOTE:
178 return font.stringWidth(fs);
181 else if (c == LyXParagraph::META_INSET) {
182 Inset *tmpinset= par->GetInset(pos);
184 return par->GetInset(pos)->Width(font);
188 } else if (IsSeparatorChar(c))
190 else if (IsNewlineChar(c))
192 return font.width(c);
197 // Returns the paragraph position of the last character in the specified row
198 LyXParagraph::size_type LyXText::RowLast(Row const * row) const
201 return row->par->Last() - 1;
202 else if (row->next->par != row->par)
203 return row->par->Last() - 1;
205 return row->next->pos - 1;
209 LyXDirection BufferParams::getDocumentDirection() const
211 return (lyxrc->rtl_support && language == "hebrew")
212 ? LYX_DIR_RIGHT_TO_LEFT : LYX_DIR_LEFT_TO_RIGHT;
215 LyXDirection LyXParagraph::getParDirection() const
217 if (!lyxrc->rtl_support || table)
218 return LYX_DIR_LEFT_TO_RIGHT;
221 return (getFont(0).direction() == LyXFont::RTL_DIR)
222 ? LYX_DIR_RIGHT_TO_LEFT : LYX_DIR_LEFT_TO_RIGHT;
224 return current_view->buffer()->params.getDocumentDirection();
227 LyXDirection LyXFont::getFontDirection() const
229 if (lyxrc->rtl_support
230 && direction() == LyXFont::RTL_DIR
231 && latex() != LyXFont::ON)
232 return LYX_DIR_RIGHT_TO_LEFT;
234 return LYX_DIR_LEFT_TO_RIGHT;
238 LyXParagraph::getLetterDirection(LyXParagraph::size_type pos) const
240 if (!lyxrc->rtl_support)
241 return LYX_DIR_LEFT_TO_RIGHT;
243 LyXDirection direction = getFont(pos).getFontDirection();
244 if (IsLineSeparator(pos) && 0 < pos && pos < Last() - 1
245 && !IsLineSeparator(pos + 1)
246 && !(table && IsNewline(pos + 1))
247 && (getFont(pos - 1).getFontDirection() != direction
248 || getFont(pos + 1).getFontDirection() != direction))
249 return getParDirection();
255 void LyXText::ComputeBidiTables(Row * row) const
258 if (!lyxrc->rtl_support) {
262 LyXParagraph::size_type last = RowLast(row);
263 bidi_start = row->pos;
265 if (bidi_start > last) {
270 if (last + 2 - bidi_start >
271 static_cast<LyXParagraph::size_type>(log2vis_list.size())) {
272 LyXParagraph::size_type new_size =
273 (last + 2 - bidi_start < 500) ?
274 500 : 2 * (last + 2 - bidi_start);
275 log2vis_list.resize(new_size);
276 vis2log_list.resize(new_size);
279 vis2log_list[last + 1 - bidi_start] = -1;
280 log2vis_list[last + 1 - bidi_start] = -1;
282 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
283 if (main_body > 0 && row->pos < main_body - 1 && main_body - 1 <= last
284 && row->par->IsLineSeparator(main_body - 1)) {
285 // This is needed in case there is a direction change in
286 // the label which is continued into the main body
287 if (row->par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) {
288 ComputeBidiTablesFromTo(row, bidi_start,
290 log2vis_list[main_body - 1 - bidi_start] =
292 vis2log_list[main_body - 1 - bidi_start] =
294 if (main_body <= last)
295 ComputeBidiTablesFromTo(row,
298 ComputeBidiTablesFromTo(row, bidi_start,
300 last - main_body + 2);
301 log2vis_list[main_body - 1 - bidi_start] =
302 last - main_body + 1 + bidi_start;
303 vis2log_list[last - main_body + 1 - bidi_start] =
305 if (main_body <= last)
306 ComputeBidiTablesFromTo(row, main_body,
310 ComputeBidiTablesFromTo(row, bidi_start, last, 0);
314 void LyXText::ComputeBidiTablesFromTo(Row * row,
315 LyXParagraph::size_type from,
316 LyXParagraph::size_type to,
317 LyXParagraph::size_type offset) const
319 LyXParagraph::size_type vpos, old_lpos, stack[2];
320 LyXDirection par_direction = row->par->getParDirection();
321 LyXDirection direction = par_direction;
322 LyXParagraph::size_type lpos = from;
326 if (row->par->getLetterDirection(lpos) == direction) {
327 log2vis_list[lpos - bidi_start] = direction;
331 (level == 1 && direction == LYX_DIR_RIGHT_TO_LEFT
332 && row->par->getFont(lpos).direction() ==
334 && row->par->getFont(lpos).latex() ==
336 // The last check is needed when the
338 stack[level++] = lpos;
340 old_lpos = stack[--level];
341 log2vis_list[old_lpos - bidi_start] =
342 log2vis_list[lpos - bidi_start] =
343 (old_lpos - lpos) * direction;
346 direction = static_cast<LyXDirection>(-direction);
351 old_lpos = stack[--level];
352 log2vis_list[old_lpos - bidi_start] =
353 (old_lpos - (to + 1)) * direction;
354 direction = static_cast<LyXDirection>(-direction);
357 vpos = (par_direction == LYX_DIR_LEFT_TO_RIGHT)
360 for (lpos = from; lpos <= to; ++lpos) {
361 vpos += log2vis_list[lpos - bidi_start];
362 vis2log_list[vpos - bidi_start] = lpos;
363 log2vis_list[lpos - bidi_start] = vpos;
369 void LyXText::draw(Row const * row,
370 LyXParagraph::size_type & vpos,
371 int offset, float & x)
373 Painter & pain = owner_->painter();
375 LyXParagraph::size_type pos = vis2log(vpos);
376 char c = row->par->GetChar(pos);
378 if (IsNewlineChar(c)) {
380 // Draw end-of-line marker
381 LyXFont font = GetFont(row->par, pos);
382 int wid = font.width('n');
383 int asc = font.maxAscent();
384 int y = offset + row->baseline;
388 if (row->par->getLetterDirection(pos) == LYX_DIR_LEFT_TO_RIGHT) {
389 xp[0] = int(x + wid * 0.375);
390 yp[0] = int(y - 0.875 * asc * 0.75);
393 yp[1] = int(y - 0.500 * asc * 0.75);
395 xp[2] = int(x + wid * 0.375);
396 yp[2] = int(y - 0.125 * asc * 0.75);
398 pain.lines(xp, yp, 3, LColor::eolmarker);
401 yp[0] = int(y - 0.500 * asc * 0.75);
403 xp[1] = int(x + wid);
404 yp[1] = int(y - 0.500 * asc * 0.75);
406 xp[2] = int(x + wid);
407 yp[2] = int(y - asc * 0.75);
409 pain.lines(xp, yp, 3, LColor::eolmarker);
411 xp[0] = int(x + wid * 0.625);
412 yp[0] = int(y - 0.875 * asc * 0.75);
414 xp[1] = int(x + wid);
415 yp[1] = int(y - 0.500 * asc * 0.75);
417 xp[2] = int(x + wid * 0.625);
418 yp[2] = int(y - 0.125 * asc * 0.75);
420 pain.lines(xp, yp, 3, LColor::eolmarker);
422 xp[0] = int(x + wid);
423 yp[0] = int(y - 0.500 * asc * 0.75);
426 yp[1] = int(y - 0.500 * asc * 0.75);
429 yp[2] = int(y - asc * 0.75);
431 pain.lines(xp, yp, 3, LColor::eolmarker);
436 if (row->par->getLetterDirection(pos) == LYX_DIR_LEFT_TO_RIGHT) {
437 p[0].x = int(x + wid*0.375); p[0].y = int(y - 0.875*asc*0.75);
438 p[1].x = int(x); p[1].y = int(y - 0.500*asc*0.75);
439 p[2].x = int(x + wid*0.375); p[2].y = int(y - 0.125*asc*0.75);
440 scr.drawLines(::getGC(gc_new_line), p, 3);
442 p[0].x = int(x); p[0].y = int(y - 0.500*asc*0.75);
443 p[1].x = int(x + wid); p[1].y = int(y - 0.500*asc*0.75);
444 p[2].x = int(x + wid); p[2].y = int(y - asc*0.75);
445 scr.drawLines(::getGC(gc_new_line), p, 3);
447 p[0].x = int(x + wid*0.625); p[0].y = int(y - 0.875*asc*0.75);
448 p[1].x = int(x + wid); p[1].y = int(y - 0.500*asc*0.75);
449 p[2].x = int(x + wid*0.625); p[2].y = int(y - 0.125*asc*0.75);
450 scr.drawLines(::getGC(gc_new_line), p, 3);
452 p[0].x = int(x + wid); p[0].y = int(y - 0.500*asc*0.75);
453 p[1].x = int(x); p[1].y = int(y - 0.500*asc*0.75);
454 p[2].x = int(x); p[2].y = int(y - asc*0.75);
455 scr.drawLines(::getGC(gc_new_line), p, 3);
462 LyXFont font = GetFont(row->par, pos);
463 LyXFont font2 = font;
465 if (c == LyXParagraph::META_FOOTNOTE
466 || c == LyXParagraph::META_MARGIN
467 || c == LyXParagraph::META_FIG
468 || c == LyXParagraph::META_TAB
469 || c == LyXParagraph::META_WIDE_FIG
470 || c == LyXParagraph::META_WIDE_TAB
471 || c == LyXParagraph::META_ALGORITHM) {
474 case LyXParagraph::META_MARGIN:
476 // Draw a sign at the left margin!
478 .text((LYX_PAPER_MARGIN - font.width('!'))/2,
479 offset + row->baseline, "!", 1, font);
481 case LyXParagraph::META_FIG:
484 case LyXParagraph::META_TAB:
487 case LyXParagraph::META_ALGORITHM:
490 case LyXParagraph::META_WIDE_FIG:
493 case LyXParagraph::META_WIDE_TAB:
496 case LyXParagraph::META_FOOTNOTE:
503 // calculate the position of the footnotemark
504 int y = (row->baseline - font2.maxAscent()
507 font.setColor(LColor::footnote);
511 // draw it and set new x position
513 pain.text(int(x), offset + y, fs, font);
514 x += pain.width(fs, font);
515 pain.line(int(tmpx), offset + row->baseline,
516 int(x), offset + row->baseline,
522 } else if (c == LyXParagraph::META_INSET) {
523 Inset * tmpinset = row->par->GetInset(pos);
525 tmpinset->draw(owner_->painter(), font,
526 offset + row->baseline, x);
531 /* usual characters, no insets */
533 // Collect character that we can draw in one command
535 // This is dirty, but fast. Notice that it will never be too small.
536 // For the record, I'll note that Microsoft Word has a limit
537 // of 768 here. We have none :-) (Asger)
538 // Ok. I am the first to admit that the use of std::string will be
539 // a tiny bit slower than using a POD char array. However, I claim
540 // that this slowdown is so small that it is close to inperceptive.
541 // So IMHO we should go with the easier and clearer implementation.
542 // And even if 1024 is a large number here it might overflow, string
543 // will only overflow if the machine is out of memory...
544 static string textstring;
548 LyXParagraph::size_type last = RowLast(row);
550 while (vpos <= last &&
551 (pos = vis2log(vpos)) >= 0
552 && static_cast<unsigned char>(c = row->par->GetChar(pos)) > ' '
553 && font2 == GetFont(row->par, pos)) {
560 // If monochrome and LaTeX mode, provide reverse background
562 font.latex() == LyXFont::ON) {
563 int a = font.maxAscent();
564 int d = font.maxDescent();
565 scr.fillRectangle(gc_copy, int(tmpx),
566 offset + row->baseline - a,
567 font.textWidth(textstring.c_str(),
568 textstring.length()), a + d);
572 // Draw text and set the new x position
573 pain.text(int(x), offset + row->baseline, textstring, font);
574 x += pain.width(textstring, font);
576 // what about underbars?
577 if (font.underbar() == LyXFont::ON && font.latex() != LyXFont::ON) {
578 pain.line(tmpx, offset + row->baseline + 2,
579 x, offset + row->baseline + 2);
583 // If we want ulem.sty support, drawing
584 // routines should go here. (Asger)
585 // Why shouldn't LyXFont::drawText handle it internally?
588 void LyXText::Draw(Row const * row, LyXParagraph::size_type & vpos,
589 LyXScreen & scr, int offset, float & x)
591 LyXParagraph::size_type pos = vis2log(vpos);
592 char c = row->par->GetChar(pos);
594 if (IsNewlineChar(c)) {
596 // Draw end-of-line marker
598 LyXFont font = GetFont(row->par, pos);
599 int asc = font.maxAscent();
600 int wid = font.width('n');
601 int y = (offset + row->baseline);
603 if (row->par->getLetterDirection(pos) == LYX_DIR_LEFT_TO_RIGHT) {
604 p[0].x = int(x + wid*0.375); p[0].y = int(y - 0.875*asc*0.75);
605 p[1].x = int(x); p[1].y = int(y - 0.500*asc*0.75);
606 p[2].x = int(x + wid*0.375); p[2].y = int(y - 0.125*asc*0.75);
607 scr.drawLines(::getGC(gc_new_line), p, 3);
609 p[0].x = int(x); p[0].y = int(y - 0.500*asc*0.75);
610 p[1].x = int(x + wid); p[1].y = int(y - 0.500*asc*0.75);
611 p[2].x = int(x + wid); p[2].y = int(y - asc*0.75);
612 scr.drawLines(::getGC(gc_new_line), p, 3);
614 p[0].x = int(x + wid*0.625); p[0].y = int(y - 0.875*asc*0.75);
615 p[1].x = int(x + wid); p[1].y = int(y - 0.500*asc*0.75);
616 p[2].x = int(x + wid*0.625); p[2].y = int(y - 0.125*asc*0.75);
617 scr.drawLines(::getGC(gc_new_line), p, 3);
619 p[0].x = int(x + wid); p[0].y = int(y - 0.500*asc*0.75);
620 p[1].x = int(x); p[1].y = int(y - 0.500*asc*0.75);
621 p[2].x = int(x); p[2].y = int(y - asc*0.75);
622 scr.drawLines(::getGC(gc_new_line), p, 3);
628 LyXFont font = GetFont(row->par, pos);
629 LyXFont font2 = font;
631 if (c == LyXParagraph::META_FOOTNOTE
632 || c == LyXParagraph::META_MARGIN
633 || c == LyXParagraph::META_FIG
634 || c == LyXParagraph::META_TAB
635 || c == LyXParagraph::META_WIDE_FIG
636 || c == LyXParagraph::META_WIDE_TAB
637 || c == LyXParagraph::META_ALGORITHM) {
640 case LyXParagraph::META_MARGIN:
642 // Draw a sign at the left margin!
643 scr.drawText(font, "!", 1, offset + row->baseline,
644 (LYX_PAPER_MARGIN - font.width('!'))/2);
646 case LyXParagraph::META_FIG:
649 case LyXParagraph::META_TAB:
652 case LyXParagraph::META_ALGORITHM:
655 case LyXParagraph::META_WIDE_FIG:
658 case LyXParagraph::META_WIDE_TAB:
661 case LyXParagraph::META_FOOTNOTE:
668 // calculate the position of the footnotemark
669 int y = (row->baseline - font2.maxAscent()
673 font.setColor(LColor::footnote);
675 font.setColor(LyXFont::RED);
680 // draw it and set new x position
681 x += scr.drawString(font, fs, offset + y, int(x));
683 scr.drawLine(gc_foot, offset + row->baseline,
684 int(tmpx), int(x - tmpx));
688 } else if (c == LyXParagraph::META_INSET) {
689 Inset * tmpinset = row->par->GetInset(pos);
691 tmpinset->Draw(font, scr, offset + row->baseline, x);
696 /* usual characters, no insets */
698 // Collect character that we can draw in one command
700 // This is dirty, but fast. Notice that it will never be too small.
701 // For the record, I'll note that Microsoft Word has a limit
702 // of 768 here. We have none :-) (Asger)
703 // Ok. I am the first to admit that the use of std::string will be
704 // a tiny bit slower than using a POD char array. However, I claim
705 // that this slowdown is so small that it is close to inperceptive.
706 // So IMHO we should go with the easier and clearer implementation.
707 // And even if 1024 is a large number here it might overflow, string
708 // will only overflow if the machine is out of memory...
709 static string textstring;
713 LyXParagraph::size_type last = RowLast(row);
715 while (vpos <= last &&
716 (pos = vis2log(vpos)) >= 0
717 && static_cast<unsigned char>(c = row->par->GetChar(pos)) > ' '
718 && font2 == GetFont(row->par, pos)) {
724 // If monochrome and LaTeX mode, provide reverse background
726 font.latex() == LyXFont::ON) {
727 int a = font.maxAscent();
728 int d = font.maxDescent();
729 scr.fillRectangle(gc_copy, int(tmpx),
730 offset + row->baseline - a,
731 font.textWidth(textstring.c_str(),
732 textstring.length()), a + d);
735 // Draw text and set the new x position
736 x += scr.drawText(font, textstring.c_str(), textstring.length(),
737 offset + row->baseline,
740 // what about underbars?
741 if (font.underbar() == LyXFont::ON && font.latex() != LyXFont::ON) {
742 scr.drawLine(gc_copy, offset + row->baseline + 2,
743 int(tmpx), int(x - tmpx));
746 // If we want ulem.sty support, drawing
747 // routines should go here. (Asger)
748 // Why shouldn't LyXFont::drawText handle it internally?
753 // Returns the left beginning of the text.
754 // This information cannot be taken from the layouts-objekt, because in
755 // LaTeX the beginning of the text fits in some cases (for example sections)
756 // exactly the label-width.
757 int LyXText::LeftMargin(Row const * row) const
759 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
760 row->par->GetLayout());
762 string parindent = layout.parindent;
764 /* table stuff -- begin */
767 /* table stuff -- end */
769 int x = LYX_PAPER_MARGIN;
771 x += textclasslist.TextClass(parameters->textclass)
773 .signedStringWidth(textclasslist
774 .TextClass(parameters->textclass)
777 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
778 LyXFont font(LyXFont::ALL_SANE);
779 font.setSize(LyXFont::SIZE_SMALL);
780 x += font.textWidth("Mwide-figM", 10) + LYX_PAPER_MARGIN/2;
783 // this is the way, LyX handles the LaTeX-Environments.
784 // I have had this idea very late, so it seems to be a
785 // later added hack and this is true
786 if (!row->par->GetDepth()) {
787 if (!row->par->GetLayout()) {
788 // find the previous same level paragraph
789 if (row->par->FirstPhysicalPar()->Previous()) {
790 LyXParagraph * newpar = row->par
791 ->DepthHook(row->par->GetDepth());
793 textclasslist.Style(parameters->textclass,
800 // find the next level paragraph
802 LyXParagraph * newpar = row->par->DepthHook(row->par->GetDepth()-1);
804 // make a corresponding row. Needed to call LeftMargin()
806 // check wether it is a sufficent paragraph
807 if (newpar && newpar->footnoteflag == row->par->footnoteflag
809 .Style(parameters->textclass,
810 newpar->GetLayout()).isEnvironment()) {
812 dummyrow.par = newpar;
813 dummyrow.pos = newpar->Last();
814 x = LeftMargin(&dummyrow);
816 // this is no longer an error, because this function
817 // is used to clear impossible depths after changing
818 // a layout. Since there is always a redo,
819 // LeftMargin() is always called
820 row->par->FirstPhysicalPar()->depth = 0;
823 if (newpar && !row->par->GetLayout()) {
824 if (newpar->FirstPhysicalPar()->noindent)
827 parindent = textclasslist
828 .Style(parameters->textclass,
829 newpar->GetLayout()).parindent;
834 LyXFont labelfont = GetFont(row->par, -2);
835 switch (layout.margintype) {
837 if (!layout.leftmargin.empty()) {
839 .TextClass(parameters->textclass)
841 .signedStringWidth(layout.leftmargin);
843 if (!row->par->GetLabestring().empty()) {
844 x += labelfont.signedStringWidth(layout.labelindent);
845 x += labelfont.stringWidth(row->par->GetLabestring());
846 x += labelfont.stringWidth(layout.labelsep);
850 x += labelfont.signedStringWidth(layout.labelindent);
851 if (row->pos >= BeginningOfMainBody(row->par)) {
852 if (!row->par->GetLabelWidthString().empty()) {
854 .stringWidth(row->par
855 ->GetLabelWidthString());
856 x += labelfont.stringWidth(layout.labelsep);
861 x += textclasslist.TextClass(parameters->textclass)
862 .defaultfont().signedStringWidth(layout.leftmargin) * 4
863 / (row->par->GetDepth() + 4);
865 case MARGIN_FIRST_DYNAMIC:
866 if (layout.labeltype == LABEL_MANUAL) {
867 if (row->pos >= BeginningOfMainBody(row->par)) {
869 .signedStringWidth(layout.leftmargin);
872 .signedStringWidth(layout.labelindent);
875 // Special case to fix problems with
877 || (layout.labeltype == LABEL_STATIC
878 && layout.latextype == LATEX_ENVIRONMENT
879 && ! row->par->IsFirstInSequence())) {
880 x += labelfont.signedStringWidth(layout.leftmargin);
881 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
882 && layout.labeltype != LABEL_BIBLIO
883 && layout.labeltype !=
884 LABEL_CENTERED_TOP_ENVIRONMENT) {
885 x += labelfont.signedStringWidth(layout.labelindent);
886 x += labelfont.stringWidth(layout.labelsep);
887 x += labelfont.stringWidth(row->par->GetLabestring());
891 case MARGIN_RIGHT_ADDRESS_BOX:
893 // ok, a terrible hack. The left margin depends on the widest
894 // row in this paragraph. Do not care about footnotes, they
895 // are *NOT* allowed in the LaTeX realisation of this layout.
897 // find the first row of this paragraph
898 Row const * tmprow = row;
899 while (tmprow->previous && tmprow->previous->par == row->par)
900 tmprow = tmprow->previous;
902 int minfill = tmprow->fill;
903 while (tmprow->next && tmprow->next->par == row->par) {
904 tmprow = tmprow->next;
905 if (tmprow->fill < minfill)
906 minfill = tmprow->fill;
909 x += textclasslist.TextClass(parameters->textclass)
910 .defaultfont().signedStringWidth(layout.leftmargin);
915 if (row->par->pextra_type == LyXParagraph::PEXTRA_INDENT) {
916 if (!row->par->pextra_widthp.empty()) {
918 atoi(row->par->pextra_widthp.c_str()) / 100;
919 } else if (!row->par->pextra_width.empty()) {
920 int xx = VSpace(row->par->pextra_width).inPixels();
923 xx = paperwidth * 80 / 100;
925 } else { // should not happen
926 LyXFont font(LyXFont::ALL_SANE);
927 x += font.stringWidth("XXXXXX");
932 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
933 align = layout.align;
935 align = row->par->FirstPhysicalPar()->align;
937 // set the correct parindent
939 if ((layout.labeltype == LABEL_NO_LABEL
940 || layout.labeltype == LABEL_TOP_ENVIRONMENT
941 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
942 || (layout.labeltype == LABEL_STATIC
943 && layout.latextype == LATEX_ENVIRONMENT
944 && ! row->par->IsFirstInSequence()))
945 && row->par == row->par->FirstPhysicalPar()
946 && align == LYX_ALIGN_BLOCK
947 && !row->par->noindent
948 && (row->par->layout ||
949 parameters->paragraph_separation ==
950 BufferParams::PARSEP_INDENT))
951 x += textclasslist.TextClass(parameters->textclass)
952 .defaultfont().signedStringWidth(parindent);
954 if (layout.labeltype == LABEL_BIBLIO) {
955 // ale970405 Right width for bibitems
957 x += bibitemMaxWidth(owner_->painter(),
959 .TextClass(parameters
963 x += bibitemMaxWidth(textclasslist
964 .TextClass(parameters
975 int LyXText::RightMargin(Row const * row) const
977 LyXLayout const & layout =
978 textclasslist.Style(parameters->textclass,
979 row->par->GetLayout());
981 int x = LYX_PAPER_MARGIN
983 .TextClass(parameters->textclass)
985 .signedStringWidth(textclasslist
986 .TextClass(parameters->textclass)
989 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
990 x += LYX_PAPER_MARGIN / 2;
993 // this is the way, LyX handles the LaTeX-Environments.
994 // I have had this idea very late, so it seems to be a
995 // later added hack and this is true
996 if (row->par->GetDepth()) {
997 // find the next level paragraph
999 LyXParagraph * newpar = row->par;
1002 newpar = newpar->FirstPhysicalPar()->Previous();
1004 newpar = newpar->FirstPhysicalPar();
1005 } while (newpar && newpar->GetDepth() >= row->par->GetDepth()
1006 && newpar->footnoteflag == row->par->footnoteflag);
1008 // make a corresponding row. Needed to call LeftMargin()
1010 // check wether it is a sufficent paragraph
1011 if (newpar && newpar->footnoteflag == row->par->footnoteflag
1012 && textclasslist.Style(parameters->textclass,
1013 newpar->GetLayout())
1016 dummyrow.par = newpar;
1018 x = RightMargin(&dummyrow);
1020 // this is no longer an error, because this function
1021 // is used to clear impossible depths after changing
1022 // a layout. Since there is always a redo,
1023 // LeftMargin() is always called
1024 row->par->FirstPhysicalPar()->depth = 0;
1028 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
1029 x += textclasslist.TextClass(parameters->textclass)
1031 .signedStringWidth(layout.rightmargin) * 4
1032 / (row->par->GetDepth() + 4);
1037 int LyXText::LabelEnd (Row const * row) const
1039 if (textclasslist.Style(parameters->textclass,
1040 row->par->GetLayout()).margintype
1044 tmprow.pos = row->par->Last();
1045 return LeftMargin(&tmprow); /* just the beginning
1048 return 0; /* LabelEnd is only needed, if the
1049 layout fills a flushleft
1054 /* table stuff -- begin*/
1055 int LyXText::NumberOfCell(LyXParagraph * par,
1056 LyXParagraph::size_type pos) const
1059 LyXParagraph::size_type tmp_pos = 0;
1060 while (tmp_pos < pos) {
1061 if (par->IsNewline(tmp_pos))
1069 int LyXText::WidthOfCell(LyXParagraph * par,
1070 LyXParagraph::size_type & pos) const
1073 while (pos < par->Last() && !par->IsNewline(pos)) {
1074 w += SingleWidth(par, pos);
1077 if (par->IsNewline(pos))
1083 bool LyXText::HitInTable(Row * row, int x) const
1086 float fill_separator, fill_hfill, fill_label_hfill;
1087 if (!row->par->table)
1089 PrepareToPrint(row, tmpx, fill_separator,
1090 fill_hfill, fill_label_hfill, false);
1091 return (x > tmpx && x < tmpx + row->par->table->WidthOfTable());
1095 bool LyXText::MouseHitInTable(int x, long y) const
1097 Row * row = GetRowNearY(y);
1098 return HitInTable(row, x);
1102 /* table stuff -- end*/
1105 // get the next breakpoint in a given paragraph
1106 LyXParagraph::size_type
1107 LyXText::NextBreakPoint(Row const * row, int width) const
1109 LyXParagraph * par = row->par;
1110 LyXParagraph::size_type pos = row->pos;
1112 /* table stuff -- begin*/
1114 while (pos < par->size()
1115 && (!par->IsNewline(pos)
1116 || !par->table->IsFirstCell(NumberOfCell(par, pos+1)))) {
1117 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
1118 par->GetInset(pos) && par->GetInset(pos)->display()){
1119 par->GetInset(pos)->display(false);
1125 /* table stuff -- end*/
1127 // position of the last possible breakpoint
1128 // -1 isn't a suitable value, but a flag
1129 LyXParagraph::size_type last_separator = -1;
1130 int left_margin = LabelEnd(row);
1131 width -= RightMargin(row);
1133 LyXParagraph::size_type main_body = BeginningOfMainBody(par);
1134 LyXLayout const & layout =
1135 textclasslist.Style(parameters->textclass, par->GetLayout());
1136 LyXParagraph::size_type i = pos;
1138 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1139 /* special code for right address boxes, only newlines count */
1140 while (i < par->Last()) {
1141 if (par->IsNewline(i)) {
1143 i = par->Last() - 1; // this means break
1145 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
1146 par->GetInset(i) && par->GetInset(i)->display()){
1147 par->GetInset(i)->display(false);
1152 // Last position is an invariant
1153 LyXParagraph::size_type const last =
1155 // this is the usual handling
1156 int x = LeftMargin(row);
1157 while (x < width && i < last) {
1158 char c = par->GetChar(i);
1159 if (IsNewlineChar(c)) {
1161 x = width; // this means break
1162 } else if (c == LyXParagraph::META_INSET &&
1163 par->GetInset(i) && par->GetInset(i)->display()){
1164 // check wether a Display() inset is
1165 // valid here. if not, change it to
1167 if (layout.isCommand()
1168 || (layout.labeltype == LABEL_MANUAL
1169 && i < BeginningOfMainBody(par))){
1170 // display istn't allowd
1171 par->GetInset(i)->display(false);
1172 x += SingleWidth(par, i, c);
1174 // inset is display. So break the line here
1178 if (IsLineSeparatorChar(par->GetChar(i+1)))
1181 last_separator = last; // to avoid extra rows
1183 last_separator = i - 1;
1184 x = width; // this means break
1187 if (IsLineSeparatorChar(c))
1189 x += SingleWidth(par, i, c);
1192 if (i == main_body) {
1193 x += GetFont(par, -2).stringWidth(layout.labelsep);
1194 if (par->IsLineSeparator(i - 1))
1195 x-= SingleWidth(par, i - 1);
1196 if (x < left_margin)
1200 // end of paragraph is always a suitable separator
1201 if (i == last && x < width)
1205 // well, if last_separator is still 0, the line isn't breakable.
1206 // don't care and cut simply at the end
1207 if (last_separator < 0) {
1211 // manual labels cannot be broken in LaTeX, do not care
1212 if (main_body && last_separator < main_body)
1213 last_separator = main_body - 1;
1215 return last_separator;
1219 // returns the minimum space a row needs on the screen in pixel
1220 int LyXText::Fill(Row const * row, int paper_width) const
1223 // get the pure distance
1224 LyXParagraph::size_type last = RowLast(row);
1225 /* table stuff -- begin */
1226 if (row->par->table) {
1227 // for tables FILL does calculate the widthes of each cell in
1229 LyXParagraph::size_type pos = row->pos;
1230 int cell = NumberOfCell(row->par, pos);
1233 row->par->table->SetWidthOfCell(cell,
1234 WidthOfCell(row->par,
1237 } while (pos <= last && !row->par->table->IsFirstCell(cell));
1238 // don't forget the very last table cell without characters
1239 if (cell == row->par->table->GetNumberOfCells() - 1)
1240 row->par->table->SetWidthOfCell(cell,
1241 WidthOfCell(row->par,
1244 return 0; /* width of table cannot be returned since
1245 * we cannot guarantee its correct value at
1248 /* table stuff -- end*/
1250 int left_margin = LabelEnd(row);
1252 // if the row ends with newline, this newline will not be relevant
1253 //if (last >= 0 && row->par->IsNewline(last))
1256 // if the row ends with a space, this space will not be relevant
1257 if (last >= 0 && row->par->IsLineSeparator(last))
1260 // special handling of the right address boxes
1261 if (textclasslist.Style(parameters->textclass,
1262 row->par->GetLayout()).margintype
1263 == MARGIN_RIGHT_ADDRESS_BOX) {
1264 int tmpfill = row->fill;
1265 row->fill = 0; // the minfill in MarginLeft()
1266 w = LeftMargin(row);
1267 row->fill = tmpfill;
1269 w = LeftMargin(row);
1271 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
1272 row->par->GetLayout());
1273 LyXParagraph::size_type main_body =
1274 BeginningOfMainBody(row->par);
1275 LyXParagraph::size_type i = row->pos;
1278 if (main_body > 0 && i == main_body) {
1279 w += GetFont(row->par, -2).
1280 stringWidth(layout.labelsep);
1281 if (row->par->IsLineSeparator(i - 1))
1282 w -= SingleWidth(row->par, i - 1);
1283 if (w < left_margin)
1286 w += SingleWidth(row->par, i);
1289 if (main_body > 0 && main_body > last) {
1290 w += GetFont(row->par, -2).stringWidth(layout.labelsep);
1291 if (last >= 0 && row->par->IsLineSeparator(last))
1292 w -= SingleWidth(row->par, last);
1293 if (w < left_margin)
1297 fill = paper_width - w - RightMargin(row);
1302 // returns the minimum space a manual label needs on the screen in pixel
1303 int LyXText::LabelFill(Row const * row) const
1305 LyXParagraph::size_type last = BeginningOfMainBody(row->par) - 1;
1306 // -1 because a label ends either with a space that is in the label,
1307 // or with the beginning of a footnote that is outside the label.
1309 // I don't understand this code in depth, but sometimes "last" is
1310 // less than 0 and this causes a crash. This fix seems to work
1311 // correctly, but I bet the real error is elsewhere. The bug is
1312 // triggered when you have an open footnote in a paragraph
1313 // environment with a manual label. (Asger)
1314 if (last < 0) last = 0;
1316 if (row->par->IsLineSeparator(last)) /* a sepearator at this end
1323 w += SingleWidth(row->par, i);
1328 if (!row->par->labelwidthstring.empty()) {
1329 fill = GetFont(row->par, -2)
1330 .stringWidth(row->par->labelwidthstring) - w;
1340 // returns the number of separators in the specified row. The separator
1341 // on the very last column doesnt count
1342 int LyXText::NumberOfSeparators(Row const * row) const
1344 int last = RowLast(row);
1346 //int main_body = BeginningOfMainBody(row->par);
1347 //if (p < main_body)
1349 // I think this is equivalent to the above. (Lgb)
1350 int p = max(row->pos, BeginningOfMainBody(row->par));
1352 for (; p < last; ++p) {
1353 if (row->par->IsSeparator(p)) {
1361 // returns the number of hfills in the specified row. The LyX-Hfill is
1362 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1363 // ignored. This is *MUCH* more usefull than not to ignore!
1364 int LyXText::NumberOfHfills(Row const * row) const
1366 int last = RowLast(row);
1367 int first = row->pos;
1368 if (first) { /* hfill *DO* count at the beginning
1370 while(first <= last && row->par->IsHfill(first))
1374 //int main_body = BeginningOfMainBody(row->par);
1375 //if (first < main_body)
1376 // first = main_body;
1377 // I think this is equivalent to the above. (Lgb)
1378 first = max(first, BeginningOfMainBody(row->par));
1380 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1381 if (row->par->IsHfill(p)) {
1389 // like NumberOfHfills, but only those in the manual label!
1390 int LyXText::NumberOfLabelHfills(Row const * row) const
1392 LyXParagraph::size_type last = RowLast(row);
1393 LyXParagraph::size_type first = row->pos;
1394 if (first) { /* hfill *DO* count at the beginning
1396 while(first < last && row->par->IsHfill(first))
1399 //LyXParagraph::size_type main_body =
1400 //BeginningOfMainBody(row->par);
1401 //if (last > main_body)
1403 // I think this is eqvialent to the above. (Lgb)
1404 last = min(last, BeginningOfMainBody(row->par));
1406 for (LyXParagraph::size_type p = first;
1407 p < last; ++p) { // last, because the end is ignored!
1408 if (row->par->IsHfill(p)) {
1416 // returns true, if a expansion is needed.
1417 // Rules are given by LaTeX
1418 bool LyXText::HfillExpansion(Row const * row_ptr,
1419 LyXParagraph::size_type pos) const
1421 // by the way, is it a hfill?
1422 if (!row_ptr->par->IsHfill(pos))
1425 // at the end of a row it does not count
1426 if (pos >= RowLast(row_ptr))
1429 // at the beginning of a row it does not count, if it is not
1430 // the first row of a paragaph
1434 // in some labels it does not count
1435 if (textclasslist.Style(parameters->textclass,
1436 row_ptr->par->GetLayout()).margintype
1438 && pos < BeginningOfMainBody(row_ptr->par))
1441 // if there is anything between the first char of the row and
1442 // the sepcified position that is not a newline and not a hfill,
1443 // the hfill will count, otherwise not
1444 LyXParagraph::size_type i = row_ptr->pos;
1445 while (i < pos && (row_ptr->par->IsNewline(i)
1446 || row_ptr->par->IsHfill(i)))
1454 void LyXText::SetHeightOfRow(Row * row_ptr) const
1456 /* get the maximum ascent and the maximum descent */
1458 float layoutasc = 0;
1459 float layoutdesc = 0;
1464 /* this must not happen before the currentrow for clear reasons.
1465 so the trick is just to set the current row onto this row */
1467 GetRow(row_ptr->par, row_ptr->pos, unused_y);
1469 /* ok , let us initialize the maxasc and maxdesc value.
1470 * This depends in LaTeX of the font of the last character
1471 * in the paragraph. The hack below is necessary because
1472 * of the possibility of open footnotes */
1474 /* Correction: only the fontsize count. The other properties
1475 are taken from the layoutfont. Nicer on the screen :) */
1477 LyXParagraph * par = row_ptr->par->LastPhysicalPar();
1478 LyXParagraph * firstpar = row_ptr->par->FirstPhysicalPar();
1480 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
1481 firstpar->GetLayout());
1483 LyXFont font = GetFont(par, par->Last()-1);
1484 LyXFont::FONT_SIZE size = font.size();
1485 font = GetFont(par, -1);
1488 LyXFont labelfont = GetFont(par, -2);
1490 int maxasc = int(font.maxAscent() *
1491 layout.spacing.getValue() *
1492 parameters->spacing.getValue());
1493 int maxdesc = int(font.maxDescent() *
1494 layout.spacing.getValue() *
1495 parameters->spacing.getValue());
1497 int pos_end = RowLast(row_ptr);
1501 // Check if any insets are larger
1502 for (pos = row_ptr->pos; pos <= pos_end; ++pos) {
1503 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_INSET) {
1504 tmpfont = GetFont(row_ptr->par, pos);
1505 tmpinset = row_ptr->par->GetInset(pos);
1507 asc = tmpinset->ascent(owner_->painter(), tmpfont);
1508 desc = tmpinset->descent(owner_->painter(), tmpfont);
1517 // Check if any custom fonts are larger (Asger)
1518 // This is not completely correct, but we can live with the small,
1519 // cosmetic error for now.
1520 LyXFont::FONT_SIZE maxsize = row_ptr->par->HighestFontInRange(row_ptr->pos,
1522 if (maxsize > font.size()) {
1523 font.setSize(maxsize);
1525 asc = font.maxAscent();
1526 desc = font.maxDescent();
1533 /* table stuff -- begin*/
1534 if (row_ptr->par->table){
1535 // stretch the rows a bit
1539 /* table stuff -- end*/
1541 // This is nicer with box insets:
1545 row_ptr->ascent_of_text = maxasc;
1547 /* is it a top line? */
1548 if (row_ptr->pos == 0
1549 && row_ptr->par == firstpar) {
1551 /* some parksips VERY EASY IMPLEMENTATION */
1552 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
1553 if (layout.isParagraph()
1554 && firstpar->GetDepth() == 0
1555 && firstpar->Previous())
1556 maxasc += parameters->getDefSkip().inPixels();
1557 else if (firstpar->Previous()
1558 && textclasslist.Style(parameters->textclass,
1559 firstpar->Previous()->GetLayout()).isParagraph()
1560 && firstpar->Previous()->GetDepth() == 0)
1561 // is it right to use defskip here too? (AS)
1562 maxasc += parameters->getDefSkip().inPixels();
1565 /* the paper margins */
1566 if (!row_ptr->par->previous)
1567 maxasc += LYX_PAPER_MARGIN;
1569 /* add the vertical spaces, that the user added */
1570 if (firstpar->added_space_top.kind() != VSpace::NONE)
1571 maxasc += int(firstpar->added_space_top.inPixels());
1573 /* do not forget the DTP-lines!
1574 * there height depends on the font of the nearest character */
1575 if (firstpar->line_top)
1576 maxasc += 2 * GetFont(firstpar, 0).ascent('x');
1578 /* and now the pagebreaks */
1579 if (firstpar->pagebreak_top)
1580 maxasc += 3 * DefaultHeight();
1582 /* this is special code for the chapter, since the label of this
1583 * layout is printed in an extra row */
1584 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1585 && parameters->secnumdepth>= 0) {
1586 labeladdon = int(labelfont.maxDescent() *
1587 layout.spacing.getValue() *
1588 parameters->spacing.getValue())
1589 + int(labelfont.maxAscent() *
1590 layout.spacing.getValue() *
1591 parameters->spacing.getValue());
1594 /* special code for the top label */
1595 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1596 || layout.labeltype == LABEL_BIBLIO
1597 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1598 && row_ptr->par->IsFirstInSequence()
1599 && !row_ptr->par->GetLabestring().empty()) {
1601 (labelfont.maxAscent() *
1602 layout.spacing.getValue() *
1603 parameters->spacing.getValue())
1604 +(labelfont.maxDescent() *
1605 layout.spacing.getValue() *
1606 parameters->spacing.getValue())
1607 + layout.topsep * DefaultHeight()
1608 + layout.labelbottomsep * DefaultHeight());
1611 /* and now the layout spaces, for example before and after a section,
1612 * or between the items of a itemize or enumerate environment */
1614 if (!firstpar->pagebreak_top) {
1615 LyXParagraph * prev = row_ptr->par->Previous();
1617 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth());
1618 if (prev && prev->GetLayout() == firstpar->GetLayout()
1619 && prev->GetDepth() == firstpar->GetDepth()
1620 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1622 layoutasc = (layout.itemsep * DefaultHeight());
1624 else if (row_ptr->previous) {
1625 tmptop = layout.topsep;
1627 if (row_ptr->previous->par->GetDepth() >= row_ptr->par->GetDepth())
1628 tmptop-= textclasslist.Style(parameters->textclass, row_ptr->previous->par->GetLayout()).bottomsep;
1631 layoutasc = (tmptop * DefaultHeight());
1633 else if (row_ptr->par->line_top){
1634 tmptop = layout.topsep;
1637 layoutasc = (tmptop * DefaultHeight());
1640 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth()-1);
1642 maxasc += int(textclasslist.Style(parameters->textclass,
1643 prev->GetLayout()).parsep * DefaultHeight());
1646 if (firstpar->Previous()
1647 && firstpar->Previous()->GetDepth() == 0
1648 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1651 else if (firstpar->Previous()){
1652 maxasc += int(layout.parsep * DefaultHeight());
1658 /* is it a bottom line? */
1659 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
1660 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
1662 /* the paper margins */
1664 maxdesc += LYX_PAPER_MARGIN;
1666 /* add the vertical spaces, that the user added */
1667 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1668 maxdesc += int(firstpar->added_space_bottom.inPixels());
1670 /* do not forget the DTP-lines!
1671 * there height depends on the font of the nearest character */
1672 if (firstpar->line_bottom)
1673 maxdesc += 2 * (GetFont(par, par->Last()-1).ascent('x'));
1675 /* and now the pagebreaks */
1676 if (firstpar->pagebreak_bottom)
1677 maxdesc += 3 * DefaultHeight();
1679 /* and now the layout spaces, for example before and after a section,
1680 * or between the items of a itemize or enumerate environment */
1681 if (!firstpar->pagebreak_bottom && row_ptr->par->Next()) {
1682 LyXParagraph * nextpar = row_ptr->par->Next();
1683 LyXParagraph * comparepar = row_ptr->par;
1687 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1688 usual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1689 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1690 if (comparepar->GetLayout()!= nextpar->GetLayout()
1691 || nextpar->GetLabelWidthString() !=
1692 comparepar->GetLabelWidthString())
1693 unusual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1695 if (unusual > usual)
1696 layoutdesc = unusual;
1700 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1702 if (comparepar->GetLayout()!= nextpar->GetLayout()
1703 || nextpar->GetLabelWidthString() !=
1704 comparepar->GetLabelWidthString())
1705 layoutdesc = int(textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1710 /* incalculate the layout spaces */
1711 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1712 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1714 /* table stuff -- begin*/
1715 if (row_ptr->par->table){
1716 maxasc += row_ptr->par->table->
1717 AdditionalHeight(NumberOfCell(row_ptr->par, row_ptr->pos));
1719 /* table stuff -- end*/
1721 /* calculate the new height of the text */
1722 height -= row_ptr->height;
1724 row_ptr->height = maxasc + maxdesc + labeladdon;
1725 row_ptr->baseline = maxasc + labeladdon;
1727 height += row_ptr->height;
1730 void LyXText::SetHeightOfRow(Row * row_ptr) const
1732 /* get the maximum ascent and the maximum descent */
1733 int asc, maxasc, desc, maxdesc, pos_end, pos, labeladdon;
1734 float layoutasc = 0;
1735 float layoutdesc = 0;
1740 /* this must not happen before the currentrow for clear reasons.
1741 so the trick is just to set the current row onto this row */
1743 GetRow(row_ptr->par, row_ptr->pos, unused_y);
1745 /* ok , let us initialize the maxasc and maxdesc value.
1746 * This depends in LaTeX of the font of the last character
1747 * in the paragraph. The hack below is necessary because
1748 * of the possibility of open footnotes */
1750 /* Correction: only the fontsize count. The other properties
1751 are taken from the layoutfont. Nicer on the screen :) */
1753 LyXParagraph * par = row_ptr->par->LastPhysicalPar();
1754 LyXParagraph * firstpar = row_ptr->par->FirstPhysicalPar();
1756 LyXLayout const & layout = textclasslist.Style(parameters->textclass, firstpar->GetLayout());
1758 LyXFont font = GetFont(par, par->Last()-1);
1759 LyXFont::FONT_SIZE size = font.size();
1760 font = GetFont(par, -1);
1763 LyXFont labelfont = GetFont(par, -2);
1765 maxasc = int(font.maxAscent() *
1766 layout.spacing.getValue() *
1767 parameters->spacing.getValue());
1768 maxdesc = int(font.maxDescent() *
1769 layout.spacing.getValue() *
1770 parameters->spacing.getValue());
1772 pos_end = RowLast(row_ptr);
1776 // Check if any insets are larger
1777 for (pos = row_ptr->pos; pos <= pos_end; ++pos) {
1778 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_INSET) {
1779 tmpfont = GetFont(row_ptr->par, pos);
1780 tmpinset = row_ptr->par->GetInset(pos);
1782 asc = tmpinset->Ascent(tmpfont);
1783 desc = tmpinset->Descent(tmpfont);
1792 // Check if any custom fonts are larger (Asger)
1793 // This is not completely correct, but we can live with the small,
1794 // cosmetic error for now.
1795 LyXFont::FONT_SIZE maxsize = row_ptr->par->HighestFontInRange(row_ptr->pos,
1797 if (maxsize > font.size()) {
1798 font.setSize(maxsize);
1800 asc = font.maxAscent();
1801 desc = font.maxDescent();
1808 /* table stuff -- begin*/
1809 if (row_ptr->par->table){
1810 // stretch the rows a bit
1814 /* table stuff -- end*/
1816 // This is nicer with box insets:
1820 row_ptr->ascent_of_text = maxasc;
1822 /* is it a top line? */
1823 if (row_ptr->pos == 0
1824 && row_ptr->par == firstpar) {
1826 /* some parksips VERY EASY IMPLEMENTATION */
1827 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
1828 if (layout.isParagraph()
1829 && firstpar->GetDepth() == 0
1830 && firstpar->Previous())
1831 maxasc += parameters->getDefSkip().inPixels();
1832 else if (firstpar->Previous()
1833 && textclasslist.Style(parameters->textclass,
1834 firstpar->Previous()->GetLayout()).isParagraph()
1835 && firstpar->Previous()->GetDepth() == 0)
1836 // is it right to use defskip here too? (AS)
1837 maxasc += parameters->getDefSkip().inPixels();
1840 /* the paper margins */
1841 if (!row_ptr->par->previous)
1842 maxasc += LYX_PAPER_MARGIN;
1844 /* add the vertical spaces, that the user added */
1845 if (firstpar->added_space_top.kind() != VSpace::NONE)
1846 maxasc += int(firstpar->added_space_top.inPixels());
1848 /* do not forget the DTP-lines!
1849 * there height depends on the font of the nearest character */
1850 if (firstpar->line_top)
1851 maxasc += 2 * GetFont(firstpar, 0).ascent('x');
1853 /* and now the pagebreaks */
1854 if (firstpar->pagebreak_top)
1855 maxasc += 3 * DefaultHeight();
1857 /* this is special code for the chapter, since the label of this
1858 * layout is printed in an extra row */
1859 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1860 && parameters->secnumdepth>= 0) {
1861 labeladdon = int(labelfont.maxDescent() *
1862 layout.spacing.getValue() *
1863 parameters->spacing.getValue())
1864 + int(labelfont.maxAscent() *
1865 layout.spacing.getValue() *
1866 parameters->spacing.getValue());
1869 /* special code for the top label */
1870 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1871 || layout.labeltype == LABEL_BIBLIO
1872 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1873 && row_ptr->par->IsFirstInSequence()
1874 && !row_ptr->par->GetLabestring().empty()) {
1876 (labelfont.maxAscent() *
1877 layout.spacing.getValue() *
1878 parameters->spacing.getValue())
1879 +(labelfont.maxDescent() *
1880 layout.spacing.getValue() *
1881 parameters->spacing.getValue())
1882 + layout.topsep * DefaultHeight()
1883 + layout.labelbottomsep * DefaultHeight());
1886 /* and now the layout spaces, for example before and after a section,
1887 * or between the items of a itemize or enumerate environment */
1889 if (!firstpar->pagebreak_top) {
1890 LyXParagraph *prev = row_ptr->par->Previous();
1892 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth());
1893 if (prev && prev->GetLayout() == firstpar->GetLayout()
1894 && prev->GetDepth() == firstpar->GetDepth()
1895 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1897 layoutasc = (layout.itemsep * DefaultHeight());
1899 else if (row_ptr->previous) {
1900 tmptop = layout.topsep;
1902 if (row_ptr->previous->par->GetDepth() >= row_ptr->par->GetDepth())
1903 tmptop-= textclasslist.Style(parameters->textclass, row_ptr->previous->par->GetLayout()).bottomsep;
1906 layoutasc = (tmptop * DefaultHeight());
1908 else if (row_ptr->par->line_top){
1909 tmptop = layout.topsep;
1912 layoutasc = (tmptop * DefaultHeight());
1915 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth()-1);
1917 maxasc += int(textclasslist.Style(parameters->textclass,
1918 prev->GetLayout()).parsep * DefaultHeight());
1921 if (firstpar->Previous()
1922 && firstpar->Previous()->GetDepth() == 0
1923 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1926 else if (firstpar->Previous()){
1927 maxasc += int(layout.parsep * DefaultHeight());
1933 /* is it a bottom line? */
1934 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
1935 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
1937 /* the paper margins */
1939 maxdesc += LYX_PAPER_MARGIN;
1941 /* add the vertical spaces, that the user added */
1942 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1943 maxdesc += int(firstpar->added_space_bottom.inPixels());
1945 /* do not forget the DTP-lines!
1946 * there height depends on the font of the nearest character */
1947 if (firstpar->line_bottom)
1948 maxdesc += 2 * (GetFont(par, par->Last()-1).ascent('x'));
1950 /* and now the pagebreaks */
1951 if (firstpar->pagebreak_bottom)
1952 maxdesc += 3 * DefaultHeight();
1954 /* and now the layout spaces, for example before and after a section,
1955 * or between the items of a itemize or enumerate environment */
1956 if (!firstpar->pagebreak_bottom && row_ptr->par->Next()) {
1957 LyXParagraph *nextpar = row_ptr->par->Next();
1958 LyXParagraph *comparepar = row_ptr->par;
1962 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1963 usual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1964 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1965 if (comparepar->GetLayout()!= nextpar->GetLayout()
1966 || nextpar->GetLabelWidthString() !=
1967 comparepar->GetLabelWidthString())
1968 unusual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1970 if (unusual > usual)
1971 layoutdesc = unusual;
1975 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1977 if (comparepar->GetLayout()!= nextpar->GetLayout()
1978 || nextpar->GetLabelWidthString() !=
1979 comparepar->GetLabelWidthString())
1980 layoutdesc = int(textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1985 /* incalculate the layout spaces */
1986 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1987 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1989 /* table stuff -- begin*/
1990 if (row_ptr->par->table){
1991 maxasc += row_ptr->par->table->
1992 AdditionalHeight(NumberOfCell(row_ptr->par, row_ptr->pos));
1994 /* table stuff -- end*/
1996 /* calculate the new height of the text */
1997 height -= row_ptr->height;
1999 row_ptr->height= maxasc+maxdesc+labeladdon;
2000 row_ptr->baseline= maxasc+labeladdon;
2002 height += row_ptr->height;
2007 /* Appends the implicit specified paragraph behind the specified row,
2008 * start at the implicit given position */
2009 void LyXText::AppendParagraph(Row * row) const
2011 bool not_ready = true;
2013 // The last character position of a paragraph is an invariant so we can
2014 // safely get it here. (Asger)
2015 int lastposition = row->par->Last();
2018 // Get the next breakpoint
2019 int z = NextBreakPoint(row, paperwidth);
2023 // Insert the new row
2024 if (z < lastposition) {
2026 InsertRow(row, row->par, z);
2033 // Set the dimensions of the row
2034 tmprow->fill = Fill(tmprow, paperwidth);
2035 SetHeightOfRow(tmprow);
2037 } while (not_ready);
2041 void LyXText::BreakAgain(Row * row) const
2043 bool not_ready = true;
2046 /* get the next breakpoint */
2047 LyXParagraph::size_type z =
2048 NextBreakPoint(row, paperwidth);
2051 if (z < row->par->Last() ) {
2052 if (!row->next || (row->next && row->next->par != row->par)) {
2055 InsertRow(row, row->par, z);
2062 not_ready = false; // the rest will not change
2068 /* if there are some rows too much, delete them */
2069 /* only if you broke the whole paragraph! */
2070 Row * tmprow2 = row;
2071 while (tmprow2->next && tmprow2->next->par == row->par) {
2072 tmprow2 = tmprow2->next;
2074 while (tmprow2 != row) {
2075 tmprow2 = tmprow2->previous;
2076 RemoveRow(tmprow2->next);
2081 /* set the dimensions of the row */
2082 tmprow->fill = Fill(tmprow, paperwidth);
2083 SetHeightOfRow(tmprow);
2084 } while (not_ready);
2088 /* this is just a little changed version of break again */
2089 void LyXText::BreakAgainOneRow(Row * row)
2091 /* get the next breakpoint */
2092 LyXParagraph::size_type z = NextBreakPoint(row, paperwidth);
2095 if (z < row->par->Last() ) {
2096 if (!row->next || (row->next && row->next->par != row->par)) {
2097 /* insert a new row */
2099 InsertRow(row, row->par, z);
2111 /* if there are some rows too much, delete them */
2112 /* only if you broke the whole paragraph! */
2113 Row * tmprow2 = row;
2114 while (tmprow2->next && tmprow2->next->par == row->par) {
2115 tmprow2 = tmprow2->next;
2117 while (tmprow2 != row) {
2118 tmprow2 = tmprow2->previous;
2119 RemoveRow(tmprow2->next);
2123 /* set the dimensions of the row */
2124 tmprow->fill = Fill(tmprow, paperwidth);
2125 SetHeightOfRow(tmprow);
2129 void LyXText::BreakParagraph(char keep_layout)
2131 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
2132 cursor.par->GetLayout());
2134 /* table stuff -- begin */
2135 if (cursor.par->table) {
2136 // breaking of tables is only allowed at the beginning or the end */
2137 if (cursor.pos && cursor.pos < cursor.par->size() &&
2138 !cursor.par->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par, cursor.pos)))
2139 return; // no breaking of tables allowed
2141 /* table stuff -- end */
2143 // this is only allowed, if the current paragraph is not empty or caption
2144 if ((cursor.par->Last() <= 0 && !cursor.par->IsDummy())
2146 layout.labeltype!= LABEL_SENSITIVE)
2149 SetUndo(Undo::INSERT,
2150 cursor.par->ParFromPos(cursor.pos)->previous,
2151 cursor.par->ParFromPos(cursor.pos)->next);
2153 /* table stuff -- begin */
2154 if (cursor.par->table) {
2155 int cell = NumberOfCell(cursor.par, cursor.pos);
2156 if (cursor.par->table->ShouldBeVeryLastCell(cell))
2157 SetCursor(cursor.par, cursor.par->text.size());
2159 /* table stuff -- end */
2161 // please break always behind a space
2162 if (cursor.pos < cursor.par->Last()
2163 && cursor.par->IsLineSeparator(cursor.pos))
2166 // break the paragraph
2170 keep_layout = layout.isEnvironment();
2171 cursor.par->BreakParagraph(cursor.pos, keep_layout);
2173 /* table stuff -- begin */
2174 if (cursor.par->table){
2175 // the table should stay with the contents
2177 cursor.par->Next()->table = cursor.par->table;
2178 cursor.par->table = 0;
2181 /* table stuff -- end */
2183 // well this is the caption hack since one caption is really enough
2184 if (layout.labeltype == LABEL_SENSITIVE){
2186 cursor.par->SetLayout(0); // set to standard-layout
2188 cursor.par->Next()->SetLayout(0); // set to standard-layout
2191 /* if the cursor is at the beginning of a row without prior newline,
2193 * This touches only the screen-update. Otherwise we would may have
2194 * an empty row on the screen */
2195 if (cursor.pos && !cursor.row->par->IsNewline(cursor.row->pos -1) &&
2196 cursor.row->pos == cursor.pos) {
2200 status = LyXText::NEED_MORE_REFRESH;
2201 refresh_row = cursor.row;
2202 refresh_y = cursor.y - cursor.row->baseline;
2204 // Do not forget the special right address boxes
2205 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
2206 while (refresh_row->previous &&
2207 refresh_row->previous->par == refresh_row->par) {
2208 refresh_row = refresh_row->previous;
2209 refresh_y -= refresh_row->height;
2212 RemoveParagraph(cursor.row);
2214 // set the dimensions of the cursor row
2215 cursor.row->fill = Fill(cursor.row, paperwidth);
2217 SetHeightOfRow(cursor.row);
2219 while (!cursor.par->Next()->table && cursor.par->Next()->Last()
2220 && cursor.par->Next()->IsNewline(0))
2221 cursor.par->Next()->Erase(0);
2223 InsertParagraph(cursor.par->Next(), cursor.row);
2225 UpdateCounters(cursor.row->previous);
2227 /* This check is necessary. Otherwise the new empty paragraph will
2228 * be deleted automatically. And it is more friendly for the user! */
2230 SetCursor(cursor.par->Next(), 0);
2232 SetCursor(cursor.par, 0);
2234 if (cursor.row->next)
2235 BreakAgain(cursor.row->next);
2241 void LyXText::OpenFootnote()
2243 LyXParagraph * endpar,* tmppar;
2246 LyXParagraph * par = cursor.par->ParFromPos(cursor.pos);
2248 /* if there is no footnote in this paragraph, just return. */
2250 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
2253 /* ok, move the cursor right before the footnote */
2255 /* just a little faster than using CursorRight() */
2256 for (cursor.pos = 0;
2257 cursor.par->ParFromPos(cursor.pos) != par; cursor.pos++);
2258 /* now the cursor is at the beginning of the physical par */
2259 SetCursor(cursor.par,
2260 cursor.pos + cursor.par->ParFromPos(cursor.pos)->text.size());
2262 /* the cursor must be exactly before the footnote */
2263 par = cursor.par->ParFromPos(cursor.pos);
2265 status = LyXText::NEED_MORE_REFRESH;
2266 refresh_row = cursor.row;
2267 refresh_y = cursor.y - cursor.row->baseline;
2269 tmppar = cursor.par;
2270 endpar = cursor.par->Next();
2273 tmppar->OpenFootnote(cursor.pos);
2274 RemoveParagraph(row);
2275 /* set the dimensions of the cursor row */
2276 row->fill = Fill(row, paperwidth);
2277 SetHeightOfRow(row);
2278 tmppar = tmppar->Next();
2280 while (tmppar != endpar) {
2282 InsertParagraph(tmppar, row);
2283 while (row->next && row->next->par == tmppar)
2285 tmppar = tmppar->Next();
2288 SetCursor(par->next, 0);
2289 sel_cursor = cursor;
2293 /* table stuff -- begin*/
2295 void LyXText::TableFeatures(int feature, string const & val) const
2297 if (!cursor.par->table)
2298 return; /* this should never happen */
2300 int actCell = NumberOfCell(cursor.par, cursor.pos);
2301 SetUndo(Undo::FINISH,
2302 cursor.par->ParFromPos(cursor.pos)->previous,
2303 cursor.par->ParFromPos(cursor.pos)->next);
2306 case LyXTable::SET_PWIDTH:
2307 cursor.par->table->SetPWidth(actCell, val);
2309 case LyXTable::SET_SPECIAL_COLUMN:
2310 case LyXTable::SET_SPECIAL_MULTI:
2311 cursor.par->table->SetAlignSpecial(actCell, val, feature);
2320 void LyXText::TableFeatures(int feature) const
2323 int setAlign = LYX_ALIGN_LEFT;
2327 if (!cursor.par->table)
2328 return; /* this should never happen */
2330 int actCell = NumberOfCell(cursor.par, cursor.pos);
2331 SetUndo(Undo::FINISH,
2332 cursor.par->ParFromPos(cursor.pos)->previous,
2333 cursor.par->ParFromPos(cursor.pos)->next);
2336 case LyXTable::ALIGN_LEFT:
2337 setAlign= LYX_ALIGN_LEFT;
2339 case LyXTable::ALIGN_RIGHT:
2340 setAlign= LYX_ALIGN_RIGHT;
2342 case LyXTable::ALIGN_CENTER:
2343 setAlign= LYX_ALIGN_CENTER;
2349 case LyXTable::APPEND_ROW: {
2350 LyXParagraph::size_type pos = cursor.pos;
2352 /* move to the next row */
2353 int cell_org = actCell;
2354 int cell = cell_org;
2356 // if there is a ContRow following this row I have to add
2357 // the row after the ContRow's
2358 if ((pos < cursor.par->Last()) &&
2359 cursor.par->table->RowHasContRow(cell_org)) {
2360 while((pos < cursor.par->Last()) &&
2361 !cursor.par->table->IsContRow(cell)) {
2362 while (pos < cursor.par->Last() &&
2363 !cursor.par->IsNewline(pos))
2365 if (pos < cursor.par->Last())
2369 while((pos < cursor.par->Last()) &&
2370 cursor.par->table->IsContRow(cell)) {
2371 while (pos < cursor.par->Last() &&
2372 !cursor.par->IsNewline(pos))
2374 if (pos < cursor.par->Last())
2379 if (pos < cursor.par->Last())
2382 while (pos < cursor.par->Last() &&
2383 (cell == cell_org || !cursor.par->table->IsFirstCell(cell))){
2384 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
2386 if (pos < cursor.par->Last())
2391 /* insert the new cells */
2392 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
2393 for (int i = 0; i < number; ++i)
2394 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
2396 /* append the row into the table */
2397 cursor.par->table->AppendRow(cell_org);
2401 case LyXTable::APPEND_CONT_ROW: {
2402 LyXParagraph::size_type pos = cursor.pos;
2403 /* move to the next row */
2404 int cell_org = actCell;
2405 int cell = cell_org;
2407 // if there is already a controw but not for this cell
2408 // the AppendContRow sets only the right values but does
2409 // not actually add a row
2410 if (cursor.par->table->RowHasContRow(cell_org) &&
2411 (cursor.par->table->CellHasContRow(cell_org)<0)) {
2412 cursor.par->table->AppendContRow(cell_org);
2416 while (pos < cursor.par->Last() &&
2418 || !cursor.par->table->IsFirstCell(cell))){
2419 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
2421 if (pos < cursor.par->Last())
2426 /* insert the new cells */
2427 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
2428 for (int i = 0; i < number; ++i)
2429 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
2431 /* append the row into the table */
2432 cursor.par->table->AppendContRow(cell_org);
2436 case LyXTable::APPEND_COLUMN: {
2437 LyXParagraph::size_type pos = 0;
2438 int cell_org = actCell;
2441 if (pos && (cursor.par->IsNewline(pos-1))){
2442 if (cursor.par->table->AppendCellAfterCell(cell_org, cell)){
2443 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
2444 if (pos <= cursor.pos)
2451 } while (pos <= cursor.par->Last());
2452 /* remember that the very last cell doesn't end with a newline.
2453 This saves one byte memory per table ;-) */
2454 if (cursor.par->table->AppendCellAfterCell(cell_org, cell))
2455 cursor.par->InsertChar(cursor.par->Last(), LyXParagraph::META_NEWLINE);
2457 /* append the column into the table */
2458 cursor.par->table->AppendColumn(cell_org);
2463 case LyXTable::DELETE_ROW:
2464 if (current_view->the_locking_inset)
2465 current_view->unlockInset(current_view->the_locking_inset);
2466 RemoveTableRow(&cursor);
2470 case LyXTable::DELETE_COLUMN: {
2471 LyXParagraph::size_type pos = 0;
2472 int cell_org = actCell;
2474 if (current_view->the_locking_inset)
2475 current_view->unlockInset(current_view->the_locking_inset);
2477 if (!pos || (cursor.par->IsNewline(pos-1))){
2478 if (cursor.par->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
2480 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
2481 cursor.par->Erase(pos);
2482 if (pos < cursor.par->Last())
2483 cursor.par->Erase(pos);
2485 cursor.par->Erase(pos - 1); // the missing newline at the end of a table
2486 --pos; // because of pos++ below
2491 } while (pos <= cursor.par->Last());
2493 /* delete the column from the table */
2494 cursor.par->table->DeleteColumn(cell_org);
2496 /* set the cursor to the beginning of the table, where else? */
2501 case LyXTable::TOGGLE_LINE_TOP:
2502 lineSet = !cursor.par->table->TopLine(actCell);
2504 cursor.par->table->SetTopLine(actCell, lineSet);
2506 LyXParagraph::size_type i;
2508 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
2509 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2510 cursor.par->table->SetTopLine(n, lineSet);
2518 case LyXTable::TOGGLE_LINE_BOTTOM:
2519 lineSet = !cursor.par->table->BottomLine(actCell);
2521 cursor.par->table->SetBottomLine(actCell, lineSet);
2523 LyXParagraph::size_type i;
2525 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2526 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2527 cursor.par->table->SetBottomLine(n, lineSet);
2535 case LyXTable::TOGGLE_LINE_LEFT:
2536 lineSet = !cursor.par->table->LeftLine(actCell);
2538 cursor.par->table->SetLeftLine(actCell, lineSet);
2540 LyXParagraph::size_type i;
2542 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
2543 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2544 cursor.par->table->SetLeftLine(n, lineSet);
2552 case LyXTable::TOGGLE_LINE_RIGHT:
2553 lineSet = !cursor.par->table->RightLine(actCell);
2555 cursor.par->table->SetRightLine(actCell, lineSet);
2558 LyXParagraph::size_type i = sel_start_cursor.pos;
2559 for (; i <= sel_end_cursor.pos; ++i) {
2560 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2561 cursor.par->table->SetRightLine(n, lineSet);
2569 case LyXTable::ALIGN_LEFT:
2570 case LyXTable::ALIGN_RIGHT:
2571 case LyXTable::ALIGN_CENTER:
2573 cursor.par->table->SetAlignment(actCell, setAlign);
2576 LyXParagraph::size_type i = sel_start_cursor.pos;
2577 for (; i <= sel_end_cursor.pos; ++i) {
2578 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2579 cursor.par->table->SetAlignment(n, setAlign);
2587 case LyXTable::DELETE_TABLE:
2588 SetCursorIntern(cursor.par, 0);
2589 delete cursor.par->table;
2590 cursor.par->table = 0;
2591 // temporary: Should put table in simple_cut_buffer (with before and after
2592 // dummy-paragraph !!
2593 // not necessar anymore with UNDO :)
2594 for (LyXParagraph::size_type i =
2595 cursor.par->text.size() - 1; i >= 0; --i)
2596 cursor.par->Erase(i);
2600 case LyXTable::MULTICOLUMN: {
2602 // check wether we are completly in a multicol
2603 int multicol = cursor.par->table->IsMultiColumn(actCell);
2604 if (multicol && selection && sel_start_cursor.row == sel_end_cursor.row){
2605 multicol = NumberOfCell(sel_start_cursor.par, sel_start_cursor.pos)
2606 == NumberOfCell(sel_end_cursor.par, sel_end_cursor.pos);
2610 int newlines = cursor.par->table->UnsetMultiColumn(actCell);
2611 LyXParagraph::size_type pos = cursor.pos;
2612 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
2614 for (; newlines; --newlines)
2615 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
2620 // selection must be in one row (or no selection)
2622 cursor.par->table->SetMultiColumn(NumberOfCell(cursor.par,
2629 if (sel_start_cursor.row == sel_end_cursor.row){
2630 LyXParagraph::size_type i;
2632 for (i = sel_start_cursor.pos;
2633 i < sel_end_cursor.pos; ++i){
2634 if (sel_start_cursor.par->IsNewline(i)){
2635 sel_start_cursor.par->Erase(i);
2636 // check for double-blanks
2637 if ((i && !sel_start_cursor.par->IsLineSeparator(i-1))
2639 (i < sel_start_cursor.par->Last()
2640 && !sel_start_cursor.par->IsLineSeparator(i)))
2641 sel_start_cursor.par->InsertChar(i, ' ');
2643 sel_end_cursor.pos--;
2650 SetMultiColumn(NumberOfCell(sel_start_cursor.par,
2651 sel_start_cursor.pos),
2653 cursor.pos = sel_start_cursor.pos;
2658 WriteAlert(_("Impossible Operation!"),
2659 _("Multicolumns can only be horizontally."),
2666 case LyXTable::SET_ALL_LINES:
2668 case LyXTable::UNSET_ALL_LINES:
2670 cursor.par->table->SetAllLines(NumberOfCell(cursor.par,
2674 LyXParagraph::size_type i;
2676 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2677 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2678 cursor.par->table->SetAllLines(n, setLines);
2685 case LyXTable::SET_LONGTABLE:
2686 cursor.par->table->SetLongTable(true);
2688 case LyXTable::UNSET_LONGTABLE:
2689 cursor.par->table->SetLongTable(false);
2691 case LyXTable::SET_ROTATE_TABLE:
2692 cursor.par->table->SetRotateTable(true);
2694 case LyXTable::UNSET_ROTATE_TABLE:
2695 cursor.par->table->SetRotateTable(false);
2697 case LyXTable::SET_ROTATE_CELL:
2699 cursor.par->table->SetRotateCell(actCell, true);
2701 LyXParagraph::size_type i;
2703 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
2704 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2705 cursor.par->table->SetRotateCell(n, true);
2711 case LyXTable::UNSET_ROTATE_CELL:
2713 cursor.par->table->SetRotateCell(actCell, false);
2716 LyXParagraph::size_type i = sel_start_cursor.pos;
2717 for (; i <= sel_end_cursor.pos; ++i) {
2718 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2719 cursor.par->table->SetRotateCell(n, false);
2725 case LyXTable::SET_LINEBREAKS:
2726 what = !cursor.par->table->Linebreaks(cursor.par->table->FirstVirtualCell(actCell));
2728 cursor.par->table->SetLinebreaks(actCell, what);
2730 LyXParagraph::size_type i;
2732 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2733 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2734 cursor.par->table->SetLinebreaks(n, what);
2740 case LyXTable::SET_LTFIRSTHEAD:
2741 cursor.par->table->SetLTHead(actCell, true);
2743 case LyXTable::SET_LTHEAD:
2744 cursor.par->table->SetLTHead(actCell, false);
2746 case LyXTable::SET_LTFOOT:
2747 cursor.par->table->SetLTFoot(actCell, false);
2749 case LyXTable::SET_LTLASTFOOT:
2750 cursor.par->table->SetLTFoot(actCell, true);
2752 case LyXTable::SET_LTNEWPAGE:
2753 what = !cursor.par->table->LTNewPage(actCell);
2754 cursor.par->table->SetLTNewPage(actCell, what);
2760 void LyXText::InsertCharInTable(char c)
2765 bool jumped_over_space;
2767 /* first check, if there will be two blanks together or a blank at
2768 * the beginning of a paragraph.
2769 * I decided to handle blanks like normal characters, the main
2770 * difference are the special checks when calculating the row.fill
2771 * (blank does not count at the end of a row) and the check here */
2773 LyXFont realtmpfont = real_current_font;
2774 LyXFont rawtmpfont = current_font; /* store the current font.
2775 * This is because of the use
2776 * of cursor movements. The moving
2777 * cursor would refresh the
2780 // Get the font that is used to calculate the baselineskip
2781 LyXParagraph::size_type const lastpos =
2783 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2785 jumped_over_space = false;
2786 if (IsLineSeparatorChar(c)) {
2788 #ifndef FIX_DOUBLE_SPACE
2789 /* avoid double blanks but insert the new blank because
2790 * of a possible font change */
2791 if (cursor.pos < lastpos &&
2792 cursor.par->IsLineSeparator(cursor.pos)) {
2793 cursor.par->Erase(cursor.pos);
2794 jumped_over_space = true;
2797 if ((cursor.pos > 0 &&
2798 cursor.par->IsLineSeparator(cursor.pos - 1))
2799 || (cursor.pos > 0 && cursor.par->IsNewline(cursor.pos - 1))
2800 || (cursor.pos == 0 &&
2801 !(cursor.par->Previous()
2802 && cursor.par->Previous()->footnoteflag
2803 == LyXParagraph::OPEN_FOOTNOTE)))
2805 } else if (IsNewlineChar(c)) {
2806 if (!IsEmptyTableCell()) {
2807 TableFeatures(LyXTable::APPEND_CONT_ROW);
2814 y = cursor.y - row->baseline;
2815 if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset
2816 * already inserted the character */
2817 cursor.par->InsertChar(cursor.pos, c);
2818 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2820 if (!jumped_over_space) {
2821 /* refresh the positions */
2823 while (tmprow->next && tmprow->next->par == row->par) {
2824 tmprow = tmprow->next;
2831 CheckParagraphInTable(cursor.par, cursor.pos);
2833 current_font = rawtmpfont;
2834 real_current_font = realtmpfont;
2836 /* check, whether the last character's font has changed. */
2837 if (cursor.pos && cursor.pos == cursor.par->Last()
2838 && rawparfont != rawtmpfont)
2839 RedoHeightOfParagraph(cursor);
2843 void LyXText::CheckParagraphInTable(LyXParagraph * par,
2844 LyXParagraph::size_type pos)
2847 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
2848 par->GetInset(pos) && par->GetInset(pos)->display()){
2849 par->GetInset(pos)->display(false);
2853 Row * row = GetRow(par, pos, y);
2855 int tmpheight = row->height;
2856 SetHeightOfRow(row);
2858 LyXParagraph::size_type tmp_pos = pos;
2859 /* update the table information */
2860 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2862 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2863 WidthOfCell(par, tmp_pos))) {
2864 LyXCursor tmpcursor = cursor;
2865 SetCursorIntern(par, pos);
2866 /* make a complete redraw */
2867 RedoDrawingOfParagraph(cursor);
2871 /* redraw only the row */
2872 LyXCursor tmpcursor = cursor;
2873 SetCursorIntern(par, pos);
2875 refresh_x = cursor.x;
2877 refresh_pos = cursor.pos;
2880 if (tmpheight == row->height)
2881 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2883 status = LyXText::NEED_MORE_REFRESH;
2885 SetCursorIntern(cursor.par, cursor.pos);
2889 void LyXText::BackspaceInTable()
2891 Row * tmprow, * row;
2894 LyXFont rawtmpfont = current_font;
2895 LyXFont realtmpfont = real_current_font;
2897 // Get the font that is used to calculate the baselineskip
2898 int const lastpos = cursor.par->Last();
2899 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2901 if (cursor.pos == 0) {
2902 /* no pasting of table paragraphs */
2906 /* this is the code for a normal backspace, not pasting
2908 SetUndo(Undo::DELETE,
2909 cursor.par->ParFromPos(cursor.pos)->previous,
2910 cursor.par->ParFromPos(cursor.pos)->next);
2914 /* some insets are undeletable here */
2915 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
2916 if (!cursor.par->GetInset(cursor.pos)->Deletable())
2921 y = cursor.y - row->baseline;
2923 /* some special code when deleting a newline. */
2924 if (cursor.par->IsNewline(cursor.pos)) {
2929 cursor.par->Erase(cursor.pos);
2931 /* refresh the positions */
2933 while (tmprow->next && tmprow->next->par == row->par) {
2934 tmprow = tmprow->next;
2938 #ifndef FIX_DOUBLE_SPACE
2939 /* delete superfluous blanks */
2940 if (cursor.pos < cursor.par->Last() - 1 &&
2941 (cursor.par->IsLineSeparator(cursor.pos))) {
2943 if (cursor.pos == BeginningOfMainBody(cursor.par)
2945 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
2946 cursor.par->Erase(cursor.pos);
2947 /* refresh the positions */
2949 while (tmprow->next &&
2950 tmprow->next->par == row->par) {
2951 tmprow = tmprow->next;
2954 if (cursor.pos) /* move one character left */
2961 CheckParagraphInTable(cursor.par, cursor.pos);
2963 /* check, wether the last characters font has changed. */
2964 if (cursor.pos && cursor.pos == cursor.par->Last()
2965 && rawparfont != rawtmpfont)
2966 RedoHeightOfParagraph(cursor);
2968 /* restore the current font
2969 * That is what a user expects! */
2970 current_font = rawtmpfont;
2971 real_current_font = realtmpfont;
2973 SetCursorIntern(cursor.par, cursor.pos);
2976 /* table stuff -- end*/
2979 /* just a macro to make some thing easier. */
2980 void LyXText::RedoParagraph() const
2983 // I suspect this version will work
2986 RedoParagraphs(cursor, cursor.par->Next());
2987 SetCursorIntern(cursor.par, cursor.pos);
2989 LyXCursor tmpcursor = cursor;
2991 RedoParagraphs(cursor, cursor.par->Next());
2992 SetCursorIntern(tmpcursor.par, tmpcursor.pos);
2997 /* insert a character, moves all the following breaks in the
2998 * same Paragraph one to the right and make a rebreak */
2999 void LyXText::InsertChar(char c)
3001 SetUndo(Undo::INSERT,
3002 cursor.par->ParFromPos(cursor.pos)->previous,
3003 cursor.par->ParFromPos(cursor.pos)->next);
3005 /* When the free-spacing option is set for the current layout,
3006 * all spaces are converted to protected spaces. */
3007 bool freeSpacingBo =
3008 textclasslist.Style(parameters->textclass,
3009 cursor.row->par->GetLayout()).free_spacing;
3011 if (freeSpacingBo && IsLineSeparatorChar(c)
3012 && (!cursor.pos || cursor.par->IsLineSeparator(cursor.pos - 1)))
3013 c = LyXParagraph::META_PROTECTED_SEPARATOR;
3015 /* table stuff -- begin*/
3016 if (cursor.par->table) {
3017 InsertCharInTable(c);
3021 /* table stuff -- end*/
3023 /* First check, if there will be two blanks together or a blank at
3024 the beginning of a paragraph.
3025 I decided to handle blanks like normal characters, the main
3026 difference are the special checks when calculating the row.fill
3027 (blank does not count at the end of a row) and the check here */
3029 // The bug is triggered when we type in a description environment:
3030 // The current_font is not changed when we go from label to main text
3031 // and it should (along with realtmpfont) when we type the space.
3032 #ifdef WITH_WARNINGS
3033 #warning There is a bug here! (Asger)
3036 LyXFont realtmpfont = real_current_font;
3037 LyXFont rawtmpfont = current_font; /* store the current font.
3038 * This is because of the use
3039 * of cursor movements. The moving
3040 * cursor would refresh the
3043 // Get the font that is used to calculate the baselineskip
3044 LyXParagraph::size_type lastpos = cursor.par->Last();
3045 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
3047 bool jumped_over_space = false;
3049 if (IsLineSeparatorChar(c)) {
3050 #ifndef FIX_DOUBLE_SPACE
3051 if (cursor.pos < lastpos
3052 && cursor.par->IsLineSeparator(cursor.pos)) {
3053 /* the user inserted a space before a space. So we
3054 * will just make a CursorRight. BUT: The font of this
3055 * space should be set to current font. That is why
3056 * we need to rebreak perhaps. If there is a protected
3057 * blank at the end of a row we have to force
3060 current_view->owner()->getMiniBuffer()
3061 ->Set(_("You cannot type two spaces this way. "
3062 " Please read the Tutorial."));
3064 // How can this ever happen?
3065 if (cursor.pos == RowLast(cursor.row)
3066 && !IsLineSeparatorChar(c))
3067 cursor.row->fill = -1; // force rebreak
3068 cursor.par->Erase(cursor.pos);
3069 jumped_over_space = true;
3071 // Seems to me that this works just as well.
3079 && cursor.par->IsLineSeparator(cursor.pos - 1))
3081 && cursor.par->IsNewline(cursor.pos - 1))
3083 && !(cursor.par->Previous()
3084 && cursor.par->Previous()->footnoteflag
3085 == LyXParagraph::OPEN_FOOTNOTE))) {
3086 if (cursor.pos == 0 )
3087 current_view->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
3089 current_view->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
3093 } else if (IsNewlineChar(c)) {
3094 if (cursor.par->FirstPhysicalPar() == cursor.par
3095 && cursor.pos <= BeginningOfMainBody(cursor.par)) {
3099 /* No newline at first position
3100 * of a paragraph or behind labels.
3101 * TeX does not allow that. */
3103 if (cursor.pos < cursor.par->Last() &&
3104 cursor.par->IsLineSeparator(cursor.pos))
3105 CursorRightIntern(); // newline always after a blank!
3106 cursor.row->fill = -1; // to force a new break
3109 // the display inset stuff
3110 if (cursor.row->par->GetChar(cursor.row->pos) == LyXParagraph::META_INSET
3111 && cursor.row->par->GetInset(cursor.row->pos)
3112 && cursor.row->par->GetInset(cursor.row->pos)->display())
3113 cursor.row->fill = -1; // to force a new break
3115 // get the cursor row fist
3116 Row * row = cursor.row;
3117 long y = cursor.y - row->baseline;
3118 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
3119 * already insertet the character */
3120 cursor.par->InsertChar(cursor.pos, c);
3121 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
3123 if (!jumped_over_space) {
3124 // refresh the positions
3126 while (tmprow->next && tmprow->next->par == row->par) {
3127 tmprow = tmprow->next;
3132 // Is there a break one row above
3133 if ((cursor.par->IsLineSeparator(cursor.pos)
3134 || cursor.par->IsNewline(cursor.pos)
3135 || cursor.row->fill == -1)
3136 && row->previous && row->previous->par == row->par) {
3137 LyXParagraph::size_type z = NextBreakPoint(row->previous,
3139 if ( z >= row->pos) {
3142 // set the dimensions of the row above
3143 row->previous->fill = Fill(row->previous, paperwidth);
3145 SetHeightOfRow(row->previous);
3147 y -= row->previous->height;
3149 refresh_row = row->previous;
3150 status = LyXText::NEED_MORE_REFRESH;
3152 BreakAgainOneRow(row);
3154 current_font = rawtmpfont;
3155 real_current_font = realtmpfont;
3156 SetCursor(cursor.par, cursor.pos + 1, false);
3157 /* cursor MUST be in row now */
3159 if (row->next && row->next->par == row->par)
3160 need_break_row = row->next;
3164 // check, wether the last characters font has changed.
3165 if (cursor.pos && cursor.pos == cursor.par->Last()
3166 && rawparfont != rawtmpfont)
3167 RedoHeightOfParagraph(cursor);
3174 /* recalculate the fill of the row */
3175 if (row->fill >= 0) /* needed because a newline
3176 * will set fill to -1. Otherwise
3177 * we would not get a rebreak! */
3178 row->fill = Fill(row, paperwidth);
3179 if (row->fill < 0 ) {
3182 refresh_x = cursor.x;
3183 refresh_pos = cursor.pos;
3184 status = LyXText::NEED_MORE_REFRESH;
3185 BreakAgainOneRow(row);
3186 /* will the cursor be in another row now? */
3187 if (RowLast(row) <= cursor.pos + 1 && row->next) {
3188 if (row->next && row->next->par == row->par)
3192 BreakAgainOneRow(row);
3194 current_font = rawtmpfont;
3195 real_current_font = realtmpfont;
3196 SetCursor(cursor.par, cursor.pos + 1, false);
3197 if (row->next && row->next->par == row->par)
3198 need_break_row = row->next;
3203 refresh_x = cursor.x;
3205 refresh_pos = cursor.pos;
3207 int tmpheight = row->height;
3208 SetHeightOfRow(row);
3209 if (tmpheight == row->height)
3210 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3212 status = LyXText::NEED_MORE_REFRESH;
3214 current_font = rawtmpfont;
3215 real_current_font = realtmpfont;
3216 SetCursor(cursor.par, cursor.pos + 1, false);
3219 /* check, wether the last characters font has changed. */
3220 if (cursor.pos && cursor.pos == cursor.par->Last()
3221 && rawparfont != rawtmpfont) {
3222 RedoHeightOfParagraph(cursor);
3224 /* now the special right address boxes */
3225 if (textclasslist.Style(parameters->textclass,
3226 cursor.par->GetLayout()).margintype
3227 == MARGIN_RIGHT_ADDRESS_BOX) {
3228 RedoDrawingOfParagraph(cursor);
3236 void LyXText::charInserted()
3238 // Here we could call FinishUndo for every 20 characters inserted.
3239 // This is from my experience how emacs does it.
3240 static unsigned int counter = 0;
3249 void LyXText::PrepareToPrint(Row * row, float & x,
3250 float & fill_separator,
3252 float & fill_label_hfill,
3257 float w = row->fill;
3259 fill_label_hfill = 0;
3261 fill_label_hfill = 0;
3263 LyXDirection direction = row->par->getParDirection();
3265 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
3266 x = RightMargin(row);
3267 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3268 LyXFont font(LyXFont::ALL_SANE);
3269 font.setSize(LyXFont::SIZE_SMALL);
3270 x += font.textWidth("Mwide-figM", 10);
3274 x = LeftMargin(row);
3276 /* is there a manual margin with a manual label */
3277 if (textclasslist.Style(parameters->textclass,
3278 row->par->GetLayout()).margintype == MARGIN_MANUAL
3279 && textclasslist.Style(parameters->textclass,
3280 row->par->GetLayout()).labeltype == LABEL_MANUAL) {
3282 nlh = NumberOfLabelHfills(row) + 1; /* one more since labels
3283 * are left aligned*/
3284 if (nlh && !row->par->GetLabelWidthString().empty()) {
3285 fill_label_hfill = LabelFill(row) / nlh;
3289 /* are there any hfills in the row? */
3290 nh = NumberOfHfills(row);
3292 /* table stuff -- begin*/
3293 if (row->par->table) {
3294 w = paperwidth - row->par->table->WidthOfTable()
3295 - x - RightMargin(row);
3296 nh = 0; /* ignore hfills in tables */
3298 /* table stuff -- end*/
3303 /* is it block, flushleft or flushright?
3304 * set x how you need it */
3306 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
3307 align = textclasslist.Style(parameters->textclass, row->par->GetLayout()).align;
3309 align = row->par->FirstPhysicalPar()->align;
3311 /* center displayed insets */
3312 if (row->par->GetChar(row->pos) == LyXParagraph::META_INSET
3313 && row->par->GetInset(row->pos)
3314 && row->par->GetInset(row->pos)->display())
3315 align = LYX_ALIGN_CENTER;
3318 case LYX_ALIGN_BLOCK:
3319 ns = NumberOfSeparators(row);
3320 if (ns && row->next && row->next->par == row->par &&
3321 !(row->next->par->IsNewline(row->next->pos-1))
3322 && !(row->next->par->GetChar(row->next->pos) == LyXParagraph::META_INSET
3323 && row->next->par->GetInset(row->next->pos)
3324 && row->next->par->GetInset(row->next->pos)->display())
3326 fill_separator = w / ns;
3327 else if (direction == LYX_DIR_RIGHT_TO_LEFT)
3330 case LYX_ALIGN_RIGHT:
3333 case LYX_ALIGN_CENTER:
3341 ComputeBidiTables(row);
3342 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
3343 LyXParagraph::size_type main_body =
3344 BeginningOfMainBody(row->par);
3345 LyXParagraph::size_type last = RowLast(row);
3347 if (row->pos <= last
3349 && last != vis2log(last)
3350 && row->par->IsLineSeparator(last)) {
3351 if (!(main_body > 0 && main_body-1 == last))
3352 x -= fill_separator+SingleWidth(row->par,last);
3353 } else if (main_body > 0 &&
3354 (main_body-1 > last ||
3355 !row->par->IsLineSeparator(main_body-1))) {
3356 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
3357 row->par->GetLayout());
3358 x += GetFont(row->par, -2).stringWidth(layout.labelsep);
3359 if (main_body-1 <= last)
3360 x += fill_label_hfill;
3365 /* important for the screen */
3368 /* the cursor set functions have a special mechanism. When they
3369 * realize, that you left an empty paragraph, they will delete it.
3370 * They also delete the corresponding row */
3372 void LyXText::CursorRightOneWord() const
3374 // treat floats, HFills and Insets as words
3375 LyXCursor tmpcursor = cursor;
3377 if (tmpcursor.pos == tmpcursor.par->Last()
3378 && tmpcursor.par->Next())
3380 tmpcursor.par = tmpcursor.par->Next();
3385 // Skip through initial nonword stuff.
3386 while ( tmpcursor.pos < tmpcursor.par->Last() &&
3387 ! tmpcursor.par->IsWord( tmpcursor.pos ) )
3389 // printf("Current pos1 %d", tmpcursor.pos) ;
3393 // Advance through word.
3394 while ( tmpcursor.pos < tmpcursor.par->Last() &&
3395 tmpcursor.par->IsWord( tmpcursor.pos ) )
3397 // printf("Current pos2 %d", tmpcursor.pos) ;
3402 SetCursor(tmpcursor.par, tmpcursor.pos);
3406 void LyXText::CursorTab() const
3408 if (cursor.par->table) {
3409 int cell = NumberOfCell(cursor.par, cursor.pos);
3410 while(cursor.par->table->IsContRow(cell)) {
3412 cell = NumberOfCell(cursor.par, cursor.pos);
3414 if (cursor.par->table->ShouldBeVeryLastCell(cell))
3415 TableFeatures(LyXTable::APPEND_ROW);
3417 LyXCursor tmpcursor = cursor;
3418 while (tmpcursor.pos < tmpcursor.par->Last()
3419 && !tmpcursor.par->IsNewline(tmpcursor.pos))
3422 if (tmpcursor.pos == tmpcursor.par->Last()){
3423 if (tmpcursor.par->Next()) {
3424 tmpcursor.par = tmpcursor.par->Next();
3430 SetCursor(tmpcursor.par, tmpcursor.pos);
3431 if (cursor.par->table) {
3432 int cell = NumberOfCell(cursor.par, cursor.pos);
3433 while (cursor.par->table->IsContRow(cell) &&
3434 !cursor.par->table->ShouldBeVeryLastCell(cell)) {
3436 while (tmpcursor.pos < tmpcursor.par->Last()
3437 && !tmpcursor.par->IsNewline(tmpcursor.pos))
3440 if (tmpcursor.pos == tmpcursor.par->Last()){
3441 if (tmpcursor.par->Next()) {
3442 tmpcursor.par = tmpcursor.par->Next();
3448 SetCursor(tmpcursor.par, tmpcursor.pos);
3449 cell = NumberOfCell(cursor.par, cursor.pos);
3455 /* -------> Skip initial whitespace at end of word and move cursor to *start*
3456 of prior word, not to end of next prior word. */
3458 void LyXText::CursorLeftOneWord() const
3460 // treat HFills, floats and Insets as words
3461 LyXCursor tmpcursor = cursor;
3462 while (tmpcursor.pos
3463 && (tmpcursor.par->IsSeparator(tmpcursor.pos - 1)
3464 || tmpcursor.par->IsKomma(tmpcursor.pos - 1))
3465 && !(tmpcursor.par->IsHfill(tmpcursor.pos - 1)
3466 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
3467 || tmpcursor.par->IsInset(tmpcursor.pos - 1)))
3471 && (tmpcursor.par->IsInset(tmpcursor.pos - 1)
3472 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
3473 || tmpcursor.par->IsHfill(tmpcursor.pos - 1))) {
3475 } else if (!tmpcursor.pos) {
3476 if (tmpcursor.par->Previous()){
3477 tmpcursor.par = tmpcursor.par->Previous();
3478 tmpcursor.pos = tmpcursor.par->Last();
3480 } else { // Here, tmpcursor != 0
3481 while (tmpcursor.pos > 0 &&
3482 tmpcursor.par->IsWord(tmpcursor.pos-1) )
3485 SetCursor(tmpcursor.par, tmpcursor.pos);
3488 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
3491 void LyXText::SelectWord()
3493 /* Move cursor to the beginning, when not already there. */
3495 && !cursor.par->IsSeparator(cursor.pos-1)
3496 && !cursor.par->IsKomma(cursor.pos-1) )
3497 CursorLeftOneWord();
3499 /* set the sel cursor */
3500 sel_cursor = cursor;
3502 while ( cursor.pos < cursor.par->Last()
3503 && !cursor.par->IsSeparator(cursor.pos)
3504 && !cursor.par->IsKomma(cursor.pos) )
3506 SetCursor( cursor.par, cursor.pos );
3508 /* finally set the selection */
3513 /* -------> Select the word currently under the cursor when:
3514 1: no selection is currently set,
3515 2: the cursor is not at the borders of the word. */
3517 int LyXText::SelectWordWhenUnderCursor()
3519 if ( selection ) return 0;
3520 if ( cursor.pos < cursor.par->Last()
3521 && !cursor.par->IsSeparator(cursor.pos)
3522 && !cursor.par->IsKomma(cursor.pos)
3524 && !cursor.par->IsSeparator(cursor.pos -1)
3525 && !cursor.par->IsKomma(cursor.pos -1) ) {
3533 // This function is only used by the spellchecker for NextWord().
3534 // It doesn't handle LYX_ACCENTs and probably never will.
3535 char * LyXText::SelectNextWord(float & value)
3537 LyXParagraph * tmppar = cursor.par;
3539 // If this is not the very first word, skip rest of
3540 // current word because we are probably in the middle
3541 // of a word if there is text here.
3542 if (cursor.pos || cursor.par->previous) {
3543 while (cursor.pos < cursor.par->Last()
3544 && cursor.par->IsLetter(cursor.pos))
3547 // Now, skip until we have real text (will jump paragraphs)
3548 while ((cursor.par->Last() > cursor.pos
3549 && (!cursor.par->IsLetter(cursor.pos)
3550 || cursor.par->getFont(cursor.pos).latex() == LyXFont::ON))
3551 || (cursor.par->Last() == cursor.pos
3552 && cursor.par->Next())){
3553 if (cursor.pos == cursor.par->Last()) {
3554 cursor.par = cursor.par->Next();
3561 // Update the value if we changed paragraphs
3562 if (cursor.par != tmppar){
3563 SetCursor(cursor.par, cursor.pos);
3564 value = float(cursor.y)/float(height);
3567 /* Start the selection from here */
3568 sel_cursor = cursor;
3572 /* and find the end of the word
3573 (optional hyphens are part of a word) */
3574 while (cursor.pos < cursor.par->Last()
3575 && (cursor.par->IsLetter(cursor.pos))
3576 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET &&
3577 cursor.par->GetInset(cursor.pos) != 0 &&
3578 cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 &&
3582 // Finally, we copy the word to a string and return it
3585 if (sel_cursor.pos < cursor.pos) {
3586 str = new char [cursor.pos - sel_cursor.pos + 2];
3587 LyXParagraph::size_type i, j;
3588 for (i = sel_cursor.pos, j = 0; i < cursor.pos; ++i) {
3589 if (cursor.par->GetChar(i) != LyXParagraph::META_INSET)
3590 str[j++] = cursor.par->GetChar(i);
3598 // This one is also only for the spellchecker
3599 void LyXText::SelectSelectedWord()
3601 /* move cursor to the beginning */
3602 SetCursor(sel_cursor.par, sel_cursor.pos);
3604 /* set the sel cursor */
3605 sel_cursor = cursor;
3609 /* now find the end of the word */
3610 while (cursor.pos < cursor.par->Last()
3611 && (cursor.par->IsLetter(cursor.pos)
3612 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET &&
3613 cursor.par->GetInset(cursor.pos) != 0 &&
3614 cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 &&
3618 SetCursor(cursor.par, cursor.pos);
3620 /* finally set the selection */
3625 /* -------> Delete from cursor up to the end of the current or next word. */
3626 void LyXText::DeleteWordForward()
3628 LyXCursor tmpcursor = cursor;
3630 if (!cursor.par->Last())
3633 /* -------> Skip initial non-word stuff. */
3634 while ( cursor.pos < cursor.par->Last()
3635 && (cursor.par->IsSeparator(cursor.pos)
3636 || cursor.par->IsKomma(cursor.pos)) )
3639 SetCursorIntern(cursor.par, cursor.pos);
3640 selection = True; // to avoid deletion
3641 CursorRightOneWord();
3642 sel_cursor = cursor;
3646 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3652 /* -------> Delete from cursor to start of current or prior word. */
3653 void LyXText::DeleteWordBackward()
3655 LyXCursor tmpcursor = cursor;
3656 if (!cursor.par->Last())
3659 selection = true; // to avoid deletion
3660 CursorLeftOneWord();
3661 sel_cursor = cursor;
3669 /* -------> Kill to end of line. */
3670 void LyXText::DeleteLineForward()
3672 LyXCursor tmpcursor = cursor;
3673 if (!cursor.par->Last())
3677 sel_cursor = cursor;
3680 if (selection == false) {
3681 DeleteWordForward();
3689 // Change the case of a word at cursor position. The meaning of action
3691 // 0 change to lowercase
3692 // 1 capitalize word
3693 // 2 change to uppercase
3694 // This function directly manipulates LyXParagraph::text because there
3695 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3696 // that it is correct. I guess part of it should be moved to
3697 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3698 // it does not access outside of the allocated array as the older
3699 // version did. (JMarc)
3700 void LyXText::ChangeWordCase(LyXText::TextCase action)
3702 LyXParagraph * tmppar = cursor.par->ParFromPos(cursor.pos);
3704 SetUndo(Undo::FINISH, tmppar->previous, tmppar->next);
3706 LyXParagraph::size_type tmppos =
3707 cursor.par->PositionInParFromPos(cursor.pos);
3708 while (tmppos < tmppar->size()) {
3709 unsigned char c = tmppar->text[tmppos];
3710 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3712 if (c != LyXParagraph::META_INSET) {
3714 case text_lowercase:
3717 case text_capitalization:
3719 action = text_lowercase;
3721 case text_uppercase:
3727 tmppar->text[tmppos] = c;
3730 CheckParagraph(tmppar, tmppos);
3731 CursorRightOneWord();
3735 void LyXText::Delete()
3737 // this is a very easy implementation
3739 LyXCursor old_cursor = cursor;
3740 int old_cur_par_id = old_cursor.par->id();
3741 int old_cur_par_prev_id = old_cursor.par->previous ?
3742 old_cursor.par->previous->id() : 0;
3744 // just move to the right
3745 CursorRightIntern();
3747 // This check is not very good...
3748 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3749 // and that can very well delete the par or par->previous in
3750 // old_cursor. Will a solution where we compare paragraph id's
3753 if ((cursor.par->previous ? cursor.par->previous->id() : 0)
3754 == old_cur_par_prev_id
3755 && cursor.par->id() != old_cur_par_id)
3756 return; // delete-empty-paragraph-mechanism has done it
3758 if (cursor.par->previous == old_cursor.par->previous
3759 && cursor.par != old_cursor.par)
3760 return; // delete-empty-paragraph-mechanism has done it
3762 // if you had success make a backspace
3763 if (old_cursor.par != cursor.par || old_cursor.pos != cursor.pos) {
3764 LyXCursor tmpcursor = cursor;
3765 cursor = old_cursor; // to make sure undo gets the right cursor position
3766 SetUndo(Undo::DELETE,
3767 cursor.par->ParFromPos(cursor.pos)->previous,
3768 cursor.par->ParFromPos(cursor.pos)->next);
3775 void LyXText::Backspace()
3777 LyXParagraph * tmppar;
3778 Row * tmprow, * row;
3782 /* table stuff -- begin */
3783 if (cursor.par->table) {
3787 /* table stuff -- end */
3789 LyXFont rawtmpfont = current_font;
3790 LyXFont realtmpfont = real_current_font;
3792 // Get the font that is used to calculate the baselineskip
3793 int const lastpos = cursor.par->Last();
3794 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
3796 if (cursor.pos == 0) {
3797 // we may paste some paragraphs
3799 // is it an empty paragraph?
3802 || (lastpos == 1 && cursor.par->IsSeparator(0)))
3803 && !(cursor.par->Next()
3804 && cursor.par->footnoteflag ==
3805 LyXParagraph::NO_FOOTNOTE
3806 && cursor.par->Next()->footnoteflag ==
3807 LyXParagraph::OPEN_FOOTNOTE)) {
3809 if (cursor.par->previous) {
3810 tmppar = cursor.par->previous->FirstPhysicalPar();
3811 if (cursor.par->GetLayout() == tmppar->GetLayout()
3812 && cursor.par->footnoteflag == tmppar->footnoteflag
3813 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3815 tmppar->line_bottom = cursor.par->line_bottom;
3816 tmppar->added_space_bottom = cursor.par->added_space_bottom;
3817 tmppar->pagebreak_bottom = cursor.par->pagebreak_bottom;
3822 // the layout things can change the height of a row !
3823 tmpheight = cursor.row->height;
3824 SetHeightOfRow(cursor.row);
3825 if (cursor.row->height != tmpheight) {
3826 refresh_y = cursor.y - cursor.row->baseline;
3827 refresh_row = cursor.row;
3828 status = LyXText::NEED_MORE_REFRESH;
3833 if (cursor.par->ParFromPos(cursor.pos)->previous){
3834 SetUndo(Undo::DELETE,
3835 cursor.par->ParFromPos(cursor.pos)->previous->previous,
3836 cursor.par->ParFromPos(cursor.pos)->next);
3838 tmppar = cursor.par;
3839 tmprow = cursor.row;
3841 /* Pasting is not allowed, if the paragraphs have different
3842 layout. I think it is a real bug of all other
3843 word processors to allow it. It confuses the user.
3844 Even so with a footnote paragraph and a non-footnote
3845 paragraph. I will not allow pasting in this case,
3846 because the user would be confused if the footnote behaves
3847 different wether it is open or closed.
3849 Correction: Pasting is always allowed with standard-layout
3851 if (cursor.par != tmppar
3852 && (cursor.par->GetLayout() == tmppar->GetLayout()
3853 || !tmppar->GetLayout())
3854 && cursor.par->footnoteflag == tmppar->footnoteflag
3855 /* table stuff -- begin*/
3856 && !cursor.par->table /* no pasting of tables */
3857 /* table stuff -- end*/
3858 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3860 cursor.par->PasteParagraph();
3863 cursor.par->IsSeparator(cursor.pos - 1)))
3864 cursor.par->InsertChar(cursor.pos, ' ');
3869 status = LyXText::NEED_MORE_REFRESH;
3870 refresh_row = cursor.row;
3871 refresh_y = cursor.y - cursor.row->baseline;
3873 // remove the lost paragraph
3874 RemoveParagraph(tmprow);
3877 AppendParagraph(cursor.row);
3878 UpdateCounters(cursor.row);
3880 // the row may have changed, block, hfills etc.
3881 SetCursor(cursor.par, cursor.pos);
3884 /* this is the code for a normal backspace, not pasting
3886 SetUndo(Undo::DELETE,
3887 cursor.par->ParFromPos(cursor.pos)->previous,
3888 cursor.par->ParFromPos(cursor.pos)->next);
3891 // some insets are undeletable here
3892 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
3893 if (!cursor.par->GetInset(cursor.pos)->Deletable())
3895 // force complete redo when erasing display insets
3896 // this is a cruel mathod but save..... Matthias
3897 if (cursor.par->GetInset(cursor.pos)->display()){
3898 cursor.par->Erase(cursor.pos);
3905 y = cursor.y - row->baseline;
3906 LyXParagraph::size_type z;
3907 /* remember that a space at the end of a row doesnt count
3908 * when calculating the fill */
3909 if (cursor.pos < RowLast(row) ||
3910 !cursor.par->IsLineSeparator(cursor.pos)) {
3911 row->fill += SingleWidth(cursor.par, cursor.pos);
3914 /* some special code when deleting a newline. This is similar
3915 * to the behavior when pasting paragraphs */
3916 if (cursor.pos && cursor.par->IsNewline(cursor.pos)) {
3917 cursor.par->Erase(cursor.pos);
3918 // refresh the positions
3920 while (tmprow->next && tmprow->next->par == row->par) {
3921 tmprow = tmprow->next;
3924 if (cursor.par->IsLineSeparator(cursor.pos - 1))
3927 if (cursor.pos < cursor.par->Last() && !cursor.par->IsSeparator(cursor.pos)) {
3928 cursor.par->InsertChar(cursor.pos, ' ');
3929 // refresh the positions
3931 while (tmprow->next && tmprow->next->par == row->par) {
3932 tmprow = tmprow->next;
3937 cursor.par->Erase(cursor.pos);
3939 // refresh the positions
3941 while (tmprow->next && tmprow->next->par == row->par) {
3942 tmprow = tmprow->next;
3946 #ifndef FIX_DOUBLE_SPACE
3947 // delete superfluous blanks
3948 if (cursor.pos < cursor.par->Last() - 1 &&
3949 (cursor.par->IsLineSeparator(cursor.pos))) {
3951 if (cursor.pos == BeginningOfMainBody(cursor.par)
3953 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
3954 cursor.par->Erase(cursor.pos);
3955 // refresh the positions
3957 while (tmprow->next &&
3958 tmprow->next->par == row->par) {
3959 tmprow = tmprow->next;
3962 if (cursor.pos) // move one character left
3968 // delete newlines at the beginning of paragraphs
3969 while (cursor.par->Last() &&
3970 cursor.par->IsNewline(cursor.pos) &&
3971 cursor.pos == BeginningOfMainBody(cursor.par)) {
3972 cursor.par->Erase(cursor.pos);
3973 // refresh the positions
3975 while (tmprow->next &&
3976 tmprow->next->par == row->par) {
3977 tmprow = tmprow->next;
3983 // is there a break one row above
3984 if (row->previous && row->previous->par == row->par) {
3985 z = NextBreakPoint(row->previous, paperwidth);
3986 if ( z >= row->pos) {
3989 tmprow = row->previous;
3991 // maybe the current row is now empty
3992 if (row->pos >= row->par->Last()) {
3997 BreakAgainOneRow(row);
3998 if (row->next && row->next->par == row->par)
3999 need_break_row = row->next;
4004 // set the dimensions of the row above
4005 y -= tmprow->height;
4006 tmprow->fill = Fill(tmprow, paperwidth);
4007 SetHeightOfRow(tmprow);
4010 refresh_row = tmprow;
4011 status = LyXText::NEED_MORE_REFRESH;
4012 current_font = rawtmpfont;
4013 real_current_font = realtmpfont;
4014 SetCursor(cursor.par, cursor.pos, false);
4015 // check, whether the last character's font has changed.
4016 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
4017 if (rawparfont != rawtmpfont)
4018 RedoHeightOfParagraph(cursor);
4023 // break the cursor row again
4024 z = NextBreakPoint(row, paperwidth);
4026 if (z != RowLast(row) ||
4027 (row->next && row->next->par == row->par &&
4028 RowLast(row) == row->par->Last() - 1)){
4030 /* it can happen that a paragraph loses one row
4031 * without a real breakup. This is when a word
4032 * is to long to be broken. Well, I don t care this
4034 if (row->next && row->next->par == row->par &&
4035 RowLast(row) == row->par->Last() - 1)
4036 RemoveRow(row->next);
4040 status = LyXText::NEED_MORE_REFRESH;
4042 BreakAgainOneRow(row);
4043 current_font = rawtmpfont;
4044 real_current_font = realtmpfont;
4045 SetCursor(cursor.par, cursor.pos, false);
4046 // cursor MUST be in row now
4048 if (row->next && row->next->par == row->par)
4049 need_break_row = row->next;
4053 // set the dimensions of the row
4054 row->fill = Fill(row, paperwidth);
4055 int tmpheight = row->height;
4056 SetHeightOfRow(row);
4057 if (tmpheight == row->height)
4058 status = LyXText::NEED_VERY_LITTLE_REFRESH;
4060 status = LyXText::NEED_MORE_REFRESH;
4063 current_font = rawtmpfont;
4064 real_current_font = realtmpfont;
4065 SetCursor(cursor.par, cursor.pos, false);
4069 // restore the current font
4070 // That is what a user expects!
4071 current_font = rawtmpfont;
4072 real_current_font = realtmpfont;
4074 // check, wether the last characters font has changed.
4075 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
4076 if (rawparfont != rawtmpfont) {
4077 RedoHeightOfParagraph(cursor);
4079 // now the special right address boxes
4080 if (textclasslist.Style(parameters->textclass,
4081 cursor.par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
4082 RedoDrawingOfParagraph(cursor);
4089 void LyXText::GetVisibleRow(int offset,
4090 Row * row_ptr, long y)
4092 /* returns a printed row */
4093 Painter & pain = owner_->painter();
4095 LyXDirection direction = row_ptr->par->getParDirection();
4096 LyXParagraph::size_type vpos, pos, pos_end;
4098 int y_top, y_bottom;
4099 float fill_separator, fill_hfill, fill_label_hfill;
4100 LyXParagraph * par, * firstpar;
4103 if (row_ptr->height <= 0) {
4104 lyxerr << "LYX_ERROR: row.height: " << row_ptr->height << endl;
4107 PrepareToPrint(row_ptr, x, fill_separator,
4108 fill_hfill, fill_label_hfill);
4110 /* initialize the pixmap */
4112 pain.fillRectangle(0, offset, paperwidth, row_ptr->height);
4114 // check for NOT FAST SELECTION
4117 !fast_selection && !mono_video &&
4120 /* selection code */
4121 if (sel_start_cursor.row == row_ptr &&
4122 sel_end_cursor.row == row_ptr) {
4123 if (sel_start_cursor.x < sel_end_cursor.x)
4124 pain.fillRectangle(sel_start_cursor.x, offset,
4125 sel_end_cursor.x - sel_start_cursor.x,
4129 pain.fillRectangle(sel_end_cursor.x, offset,
4130 sel_start_cursor.x - sel_end_cursor.x,
4133 } else if (sel_start_cursor.row == row_ptr) {
4134 if (direction == LYX_DIR_LEFT_TO_RIGHT)
4135 pain.fillRectangle(sel_start_cursor.x, offset,
4136 paperwidth - sel_start_cursor.x,
4140 pain.fillRectangle(0, offset,
4144 } else if (sel_end_cursor.row == row_ptr) {
4145 if (direction == LYX_DIR_LEFT_TO_RIGHT)
4146 pain.fillRectangle(0, offset,
4151 pain.fillRectangle(sel_end_cursor.x, offset,
4152 paperwidth - sel_end_cursor.x,
4156 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
4157 pain.fillRectangle(0, offset,
4158 paperwidth, row_ptr->height,
4161 } // end of NOT FAST SELECTION code
4163 if (row_ptr->par->appendix){
4164 pain.line(1, offset,
4165 1, offset + row_ptr->height,
4166 LColor::appendixline);
4167 pain.line(paperwidth - 2, offset,
4168 paperwidth - 2, offset + row_ptr->height,
4169 LColor::appendixline);
4172 if (row_ptr->par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4173 /* draw a marker at the left margin! */
4174 LyXFont font = GetFont(row_ptr->par, 0);
4175 int asc = font.maxAscent();
4176 int x = (LYX_PAPER_MARGIN - font.width('|')) / 2;
4177 int y1 = (offset + row_ptr->baseline);
4178 int y2 = (offset + row_ptr->baseline) - asc;
4179 pain.line(x, y1, x, y2, LColor::minipageline);
4181 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4182 LyXFont font(LyXFont::ALL_SANE);
4183 font.setSize(LyXFont::SIZE_FOOTNOTE);
4184 font.setColor(LColor::footnote);
4186 int box_x = LYX_PAPER_MARGIN;
4187 box_x += font.textWidth(" wide-tab ", 10);
4188 if (row_ptr->previous &&
4189 row_ptr->previous->par->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
4191 switch (row_ptr->par->footnotekind) {
4192 case LyXParagraph::MARGIN:
4195 case LyXParagraph::FIG:
4198 case LyXParagraph::TAB:
4201 case LyXParagraph::WIDE_FIG:
4204 case LyXParagraph::WIDE_TAB:
4207 case LyXParagraph::ALGORITHM:
4210 case LyXParagraph::FOOTNOTE:
4216 // Determine background color.
4217 gc_type back = gc_lighted;
4222 pain.fillRectangle(LYX_PAPER_MARGIN,
4224 box_x - LYX_PAPER_MARGIN,
4225 int(font.maxAscent()
4226 + font.maxDescent()),
4227 LColor::footnotebg);
4229 pain.line(LYX_PAPER_MARGIN, offset,
4230 paperwidth - LYX_PAPER_MARGIN, offset,
4231 LColor::footnoteframe);
4233 pain.text(LYX_PAPER_MARGIN,
4234 offset + int(font.maxAscent()) + 1,
4237 pain.line(LYX_PAPER_MARGIN, offset,
4239 offset + int(font.maxAscent()
4240 + font.maxDescent()),
4241 LColor::footnoteframe);
4243 pain.line(LYX_PAPER_MARGIN,
4244 offset + int(font.maxAscent()
4245 + font.maxDescent()) + 1,
4247 offset + int(font.maxAscent()
4248 + font.maxDescent()) + 1,
4249 LColor::footnoteframe);
4253 /* draw the open floats in a red box */
4254 pain.line(box_x, offset,
4255 box_x, offset + row_ptr->height,
4256 LColor::footnoteframe);
4258 pain.line(paperwidth - LYX_PAPER_MARGIN,
4260 paperwidth - LYX_PAPER_MARGIN,
4261 offset + row_ptr->height,
4262 LColor::footnoteframe);
4264 if (row_ptr->previous &&
4265 row_ptr->previous->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4266 LyXFont font(LyXFont::ALL_SANE);
4267 font.setSize(LyXFont::SIZE_FOOTNOTE);
4269 int box_x = LYX_PAPER_MARGIN;
4270 box_x += font.textWidth(" wide-tab ", 10);
4272 pain.line(box_x, offset,
4273 paperwidth - LYX_PAPER_MARGIN,
4274 offset, LColor::footnote);
4278 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
4279 row_ptr->par->GetLayout());
4280 firstpar = row_ptr->par->FirstPhysicalPar();
4283 y_bottom = row_ptr->height;
4285 /* is it a first row? */
4286 if (row_ptr->pos == 0
4287 && row_ptr->par == firstpar) {
4289 /* start of appendix? */
4290 if (row_ptr->par->start_of_appendix){
4291 pain.line(1, offset,
4292 paperwidth - 2, offset,
4293 LColor::appendixline);
4296 /* think about the margins */
4297 if (!row_ptr->previous)
4298 y_top += LYX_PAPER_MARGIN;
4300 if (row_ptr->par->pagebreak_top){ /* draw a top pagebreak */
4301 pain.line(0, offset + y_top + 2 * DefaultHeight(),
4303 offset + y_top + 2 * DefaultHeight(),
4304 LColor::pagebreak, Painter::line_onoffdash);
4305 y_top += 3 * DefaultHeight();
4308 if (row_ptr->par->added_space_top.kind() == VSpace::VFILL) {
4309 /* draw a vfill top */
4310 pain.line(0, offset + 2 + y_top,
4311 LYX_PAPER_MARGIN, offset + 2 + y_top,
4314 pain.line(0, offset + y_top + 3 * DefaultHeight(),
4316 offset + y_top + 3 * DefaultHeight(),
4319 pain.line(LYX_PAPER_MARGIN / 2, offset + 2 + y_top,
4320 LYX_PAPER_MARGIN / 2,
4321 offset + y_top + 3 * DefaultHeight(),
4324 y_top += 3 * DefaultHeight();
4327 /* think about user added space */
4328 y_top += int(row_ptr->par->added_space_top.inPixels());
4330 /* think about the parskip */
4331 /* some parskips VERY EASY IMPLEMENTATION */
4332 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
4333 if (layout.latextype == LATEX_PARAGRAPH
4334 && firstpar->GetDepth() == 0
4335 && firstpar->Previous())
4336 y_top += parameters->getDefSkip().inPixels();
4337 else if (firstpar->Previous()
4338 && textclasslist.Style(parameters->textclass,
4339 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
4340 && firstpar->Previous()->GetDepth() == 0)
4341 // is it right to use defskip here, too? (AS)
4342 y_top += parameters->getDefSkip().inPixels();
4345 if (row_ptr->par->line_top) { /* draw a top line */
4346 y_top += GetFont(row_ptr->par, 0).ascent('x');
4348 pain.line(0, offset + y_top,
4349 paperwidth, offset + y_top,
4351 Painter::line_solid,
4352 Painter::line_thick);
4354 y_top += GetFont(row_ptr->par, 0).ascent('x');
4357 /* should we print a label? */
4358 if (layout.labeltype >= LABEL_STATIC
4359 && (layout.labeltype != LABEL_STATIC
4360 || layout.latextype != LATEX_ENVIRONMENT
4361 || row_ptr->par->IsFirstInSequence())) {
4362 font = GetFont(row_ptr->par, -2);
4363 if (!row_ptr->par->GetLabestring().empty()) {
4365 string tmpstring = row_ptr->par->GetLabestring();
4367 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
4368 if (parameters->secnumdepth >= 0){
4369 /* this is special code for the chapter layout. This is printed in
4370 * an extra row and has a pagebreak at the top. */
4371 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue())
4372 + int(layout.parsep) * DefaultHeight();
4373 if (direction == LYX_DIR_RIGHT_TO_LEFT)
4374 tmpx = paperwidth - LeftMargin(row_ptr) -
4375 font.stringWidth(tmpstring);
4376 pain.text(int(tmpx),
4377 offset + row_ptr->baseline - row_ptr->ascent_of_text - maxdesc,
4381 if (direction == LYX_DIR_LEFT_TO_RIGHT)
4382 tmpx = x - font.stringWidth(layout.labelsep)
4383 - font.stringWidth(tmpstring);
4385 tmpx = paperwidth - LeftMargin(row_ptr)
4386 + font.stringWidth(layout.labelsep);
4387 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4388 LyXFont font(LyXFont::ALL_SANE);
4389 font.setSize(LyXFont::SIZE_SMALL);
4390 tmpx += font.textWidth("Mwide-figM", 10);
4394 pain.text(int(tmpx),
4395 offset + row_ptr->baseline,
4399 /* the labels at the top of an environment. More or less for bibliography */
4400 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
4401 layout.labeltype == LABEL_BIBLIO ||
4402 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
4403 if (row_ptr->par->IsFirstInSequence()) {
4404 font = GetFont(row_ptr->par, -2);
4405 if (!row_ptr->par->GetLabestring().empty()) {
4406 string tmpstring = row_ptr->par->GetLabestring();
4408 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue()
4409 + (layout.labelbottomsep * DefaultHeight()));
4412 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
4413 tmpx = ( ((direction == LYX_DIR_LEFT_TO_RIGHT)
4414 ? x : LeftMargin(row_ptr) )
4415 + paperwidth - RightMargin(row_ptr) ) / 2;
4416 tmpx -= (font.stringWidth(tmpstring)/2);
4417 } else if (direction == LYX_DIR_RIGHT_TO_LEFT)
4418 tmpx = paperwidth - LeftMargin(row_ptr) -
4419 font.stringWidth(tmpstring);
4420 pain.text(int(tmpx),
4421 offset + row_ptr->baseline
4422 - row_ptr->ascent_of_text
4428 if (layout.labeltype == LABEL_BIBLIO) { // ale970302
4429 if (row_ptr->par->bibkey) {
4430 font = GetFont(row_ptr->par, -1);
4431 if (direction == LYX_DIR_LEFT_TO_RIGHT)
4432 tmpx = x - font.stringWidth(layout.labelsep)
4433 - row_ptr->par->bibkey->width(owner_->painter(), font);
4435 tmpx = paperwidth - LeftMargin(row_ptr)
4436 + font.stringWidth(layout.labelsep);
4437 row_ptr->par->bibkey->draw(owner_->painter(),
4439 offset + row_ptr->baseline,
4445 /* is it a last row? */
4446 par = row_ptr->par->LastPhysicalPar();
4447 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
4448 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
4450 /* think about the margins */
4452 y_bottom -= LYX_PAPER_MARGIN;
4454 /* draw a bottom pagebreak */
4455 if (firstpar->pagebreak_bottom) {
4456 pain.line(0, offset + y_bottom - 2 * DefaultHeight(),
4458 offset + y_bottom - 2 * DefaultHeight(),
4459 LColor::pagebreak, Painter::line_onoffdash);
4460 y_bottom -= 3 * DefaultHeight();
4463 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
4464 /* draw a vfill bottom */
4465 pain.line(0, offset + y_bottom - 3 * DefaultHeight(),
4467 offset + y_bottom - 3 * DefaultHeight(),
4469 pain.line(0, offset + y_bottom - 2,
4471 offset + y_bottom - 2,
4473 pain.line(LYX_PAPER_MARGIN / 2,
4474 offset + y_bottom - 3 * DefaultHeight(),
4475 LYX_PAPER_MARGIN / 2,
4476 offset + y_bottom - 2,
4478 y_bottom -= 3* DefaultHeight();
4481 /* think about user added space */
4482 y_bottom -= int(firstpar->added_space_bottom.inPixels());
4484 if (firstpar->line_bottom) {
4485 /* draw a bottom line */
4486 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
4487 pain.line(0, offset + y_bottom,
4488 paperwidth, offset + y_bottom,
4489 LColor::topline, Painter::line_solid,
4490 Painter::line_thick);
4491 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
4495 /* draw the text in the pixmap */
4496 pos_end = RowLast(row_ptr);
4498 vpos = row_ptr->pos;
4499 /* table stuff -- begin*/
4500 if (row_ptr->par->table) {
4502 int cell = NumberOfCell(row_ptr->par, row_ptr->pos);
4504 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
4506 while (vpos <= pos_end) {
4507 pos = vis2log(vpos);
4508 if (row_ptr->par->IsNewline(pos)) {
4510 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
4511 /* draw the table lines, still very simple */
4512 on_off = !row_ptr->par->table->TopLine(cell);
4514 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
4515 !row_ptr->par->table->IsContRow(cell))
4516 pain.line(int(x_old),
4517 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4519 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4521 on_off ? Painter::line_onoffdash : Painter::line_solid);
4523 on_off = !row_ptr->par->table->BottomLine(cell);
4524 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
4525 row_ptr->par->table->VeryLastRow(cell))
4527 pain.line(int(x_old),
4528 offset + y_bottom - 1,
4530 offset + y_bottom - 1,
4532 on_off ? Painter::line_onoffdash : Painter::line_solid);
4534 on_off = !row_ptr->par->table->LeftLine(cell);
4536 pain.line(int(x_old),
4537 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4539 offset + y_bottom - 1,
4541 on_off ? Painter::line_onoffdash : Painter::line_solid);
4543 on_off = !row_ptr->par->table->RightLine(cell);
4545 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
4546 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4547 int(x) - row_ptr->par->table->AdditionalWidth(cell),
4548 offset + y_bottom - 1,
4550 on_off ? Painter::line_onoffdash : Painter::line_solid);
4553 /* take care about the alignment and other spaces */
4555 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
4556 if (row_ptr->par->table->IsFirstCell(cell))
4557 --cell; // little hack, sorry
4559 } else if (row_ptr->par->IsHfill(pos)) {
4563 offset + row_ptr->baseline - DefaultHeight() / 2,
4565 offset + row_ptr->baseline,
4571 if (row_ptr->par->IsSeparator(pos)) {
4573 x+= SingleWidth(row_ptr->par, pos);
4574 /* -------> Only draw protected spaces when not in
4575 * free-spacing mode. */
4576 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
4577 pain.line(int(tmpx),
4578 offset + row_ptr->baseline - 3,
4580 offset + row_ptr->baseline - 1,
4583 pain.line(int(tmpx),
4584 offset + row_ptr->baseline - 1,
4586 offset + row_ptr->baseline - 1,
4589 pain.line(int(x - 2),
4590 offset + row_ptr->baseline - 3,
4592 offset + row_ptr->baseline - 1,
4595 /* what about underbars? */
4596 font = GetFont(row_ptr->par, pos);
4597 if (font.underbar() == LyXFont::ON
4598 && font.latex() != LyXFont::ON) {
4599 pain.line(int(tmpx),
4600 offset + row_ptr->baseline + 2,
4602 offset + row_ptr->baseline + 2);
4607 draw(row_ptr, vpos, offset, x);
4611 /* do not forget the very last cell. This has no NEWLINE so
4612 * ignored by the code above*/
4613 if (cell == row_ptr->par->table->GetNumberOfCells()-1){
4614 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
4615 on_off = !row_ptr->par->table->TopLine(cell);
4617 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
4618 !row_ptr->par->table->IsContRow(cell))
4620 pain.line(int(x_old),
4621 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4623 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4625 on_off ? Painter::line_onoffdash : Painter::line_solid);
4626 on_off = !row_ptr->par->table->BottomLine(cell);
4627 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
4628 row_ptr->par->table->VeryLastRow(cell))
4630 pain.line(int(x_old),
4631 offset + y_bottom - 1,
4633 offset + y_bottom - 1,
4635 on_off ? Painter::line_onoffdash : Painter::line_solid);
4637 on_off = !row_ptr->par->table->LeftLine(cell);
4639 pain.line(int(x_old),
4640 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4642 offset + y_bottom - 1,
4644 on_off ? Painter::line_onoffdash : Painter::line_solid);
4646 on_off = !row_ptr->par->table->RightLine(cell);
4648 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
4649 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4650 int(x) - row_ptr->par->table->AdditionalWidth(cell),
4651 offset + y_bottom - 1,
4653 on_off ? Painter::line_onoffdash : Painter::line_solid);
4656 /* table stuff -- end*/
4657 LyXParagraph::size_type main_body =
4658 BeginningOfMainBody(row_ptr->par);
4659 if (main_body > 0 &&
4660 (main_body-1 > pos_end ||
4661 !row_ptr->par->IsLineSeparator(main_body-1)))
4664 while (vpos <= pos_end) {
4665 pos = vis2log(vpos);
4666 if (main_body > 0 && pos == main_body-1) {
4667 x += fill_label_hfill
4668 + GetFont(row_ptr->par, -2).stringWidth(layout.labelsep)
4669 - SingleWidth(row_ptr->par, main_body-1);
4672 if (row_ptr->par->IsHfill(pos)) {
4675 offset + row_ptr->baseline - DefaultHeight() / 2,
4677 offset + row_ptr->baseline,
4680 if (HfillExpansion(row_ptr, pos)) {
4681 if (pos >= main_body) {
4683 offset + row_ptr->baseline - DefaultHeight() / 4,
4684 int(x + fill_hfill),
4685 offset + row_ptr->baseline - DefaultHeight() / 4,
4687 Painter::line_onoffdash);
4691 offset + row_ptr->baseline - DefaultHeight() / 4,
4692 int(x + fill_label_hfill),
4693 offset + row_ptr->baseline - DefaultHeight() / 4,
4695 Painter::line_onoffdash);
4697 x += fill_label_hfill;
4700 offset + row_ptr->baseline - DefaultHeight() / 2,
4702 offset + row_ptr->baseline,
4708 if (row_ptr->par->IsSeparator(pos)) {
4710 x+= SingleWidth(row_ptr->par, pos);
4711 if (pos >= main_body)
4713 /* -------> Only draw protected spaces when not in
4714 * free-spacing mode. */
4715 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
4717 pain.line(int(tmpx),
4718 offset + row_ptr->baseline - 3,
4720 offset + row_ptr->baseline - 1,
4723 pain.line(int(tmpx),
4724 offset + row_ptr->baseline - 1,
4726 offset + row_ptr->baseline - 1,
4729 pain.line(int(x - 2),
4730 offset + row_ptr->baseline - 3,
4732 offset + row_ptr->baseline - 1,
4735 /* what about underbars? */
4736 font = GetFont(row_ptr->par, pos);
4737 if (font.underbar() == LyXFont::ON
4738 && font.latex() != LyXFont::ON) {
4739 pain.line(int(tmpx),
4740 offset + row_ptr->baseline + 2,
4742 offset + row_ptr->baseline + 2);
4747 draw(row_ptr, vpos, offset, x);
4752 // check for FAST SELECTION
4753 if (fast_selection || mono_video) {
4756 /* selection code */
4757 if (sel_start_cursor.row == row_ptr && sel_end_cursor.row == row_ptr) {
4758 scr.fillRectangle(gc_select, sel_start_cursor.x, offset,
4759 sel_end_cursor.x - sel_start_cursor.x,
4761 } else if (sel_start_cursor.row == row_ptr) {
4762 scr.fillRectangle(gc_select, sel_start_cursor.x, offset,
4763 paperwidth - sel_start_cursor.x,
4765 } else if (sel_end_cursor.row == row_ptr) {
4766 scr.fillRectangle(gc_select, 0, offset,
4769 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
4770 scr.fillRectangle(gc_select, 0, offset,
4771 paperwidth, row_ptr->height);
4776 // end of FAST SELECTION code
4781 void LyXText::GetVisibleRow(LyXScreen & scr, int offset,
4782 Row * row_ptr, long y)
4784 /* returns a printed row */
4785 LyXDirection direction = row_ptr->par->getParDirection();
4786 LyXParagraph::size_type vpos, pos, pos_end;
4788 int y_top, y_bottom;
4789 float fill_separator, fill_hfill, fill_label_hfill;
4790 LyXParagraph * par, * firstpar;
4793 if (row_ptr->height <= 0) {
4794 lyxerr << "LYX_ERROR: row.height: " << row_ptr->height << endl;
4797 PrepareToPrint(row_ptr, x, fill_separator,
4798 fill_hfill, fill_label_hfill);
4800 /* initialize the pixmap */
4802 scr.fillRectangle(gc_clear,
4803 0, offset, paperwidth, row_ptr->height);
4804 // check for NOT FAST SELECTION
4805 if (!fast_selection && !mono_video && selection) {
4806 /* selection code */
4807 if (sel_start_cursor.row == row_ptr &&
4808 sel_end_cursor.row == row_ptr) {
4809 if (sel_start_cursor.x < sel_end_cursor.x)
4810 scr.fillRectangle(gc_selection, sel_start_cursor.x,
4812 sel_end_cursor.x - sel_start_cursor.x,
4815 scr.fillRectangle(gc_selection, sel_end_cursor.x,
4817 sel_start_cursor.x - sel_end_cursor.x,
4820 else if (sel_start_cursor.row == row_ptr) {
4821 if (direction == LYX_DIR_LEFT_TO_RIGHT)
4822 scr.fillRectangle(gc_selection, sel_start_cursor.x,
4824 paperwidth - sel_start_cursor.x,
4827 scr.fillRectangle(gc_selection, 0, offset,
4828 sel_start_cursor.x, row_ptr->height);
4829 } else if (sel_end_cursor.row == row_ptr) {
4830 if (direction == LYX_DIR_LEFT_TO_RIGHT)
4831 scr.fillRectangle(gc_selection, 0, offset,
4832 sel_end_cursor.x, row_ptr->height);
4834 scr.fillRectangle(gc_selection, sel_end_cursor.x,
4836 paperwidth - sel_end_cursor.x,
4838 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
4839 scr.fillRectangle(gc_selection, 0, offset,
4840 paperwidth, row_ptr->height);
4843 } // end of NOT FAST SELECTION code
4845 if (row_ptr->par->appendix){
4846 scr.drawVerticalLine(gc_math, 1, offset, offset+row_ptr->height);
4847 scr.drawVerticalLine(gc_math, paperwidth-2 , offset, offset+row_ptr->height);
4850 if (row_ptr->par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4851 /* draw a marker at the left margin! */
4852 LyXFont font = GetFont(row_ptr->par, 0);
4853 int asc = font.maxAscent();
4854 int x = (LYX_PAPER_MARGIN - font.width('|')) / 2;
4855 int y1 = (offset + row_ptr->baseline);
4856 int y2 = (offset + row_ptr->baseline) - asc;
4858 scr.drawVerticalLine(gc_minipage, x, y1, y2);
4860 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4861 LyXFont font(LyXFont::ALL_SANE);
4862 font.setSize(LyXFont::SIZE_FOOTNOTE);
4864 font.setColor(LColor::footnote);
4866 font.setColor(LyXFont::RED);
4869 int box_x = LYX_PAPER_MARGIN;
4870 box_x += font.textWidth(" wide-tab ", 10);
4871 if (row_ptr->previous &&
4872 row_ptr->previous->par->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
4874 switch (row_ptr->par->footnotekind) {
4875 case LyXParagraph::MARGIN:
4878 case LyXParagraph::FIG:
4881 case LyXParagraph::TAB:
4884 case LyXParagraph::WIDE_FIG:
4887 case LyXParagraph::WIDE_TAB:
4890 case LyXParagraph::ALGORITHM:
4893 case LyXParagraph::FOOTNOTE:
4898 // Determine background color.
4899 gc_type back = gc_lighted;
4903 scr.fillRectangle(back, LYX_PAPER_MARGIN, offset+1,
4904 box_x - LYX_PAPER_MARGIN,
4905 int(font.maxAscent())+
4906 int(font.maxDescent()));
4908 scr.drawLine(gc_foot,
4911 paperwidth - 2*LYX_PAPER_MARGIN);
4913 scr.drawString(font, fs,
4914 offset + int(font.maxAscent())+1,
4916 scr.drawVerticalLine(gc_foot,
4920 + int(font.maxAscent())+
4921 int(font.maxDescent()));
4923 scr.drawLine(gc_foot,
4925 + int(font.maxAscent())
4926 + int(font.maxDescent()) + 1,
4927 LYX_PAPER_MARGIN, box_x - LYX_PAPER_MARGIN);
4930 /* draw the open floats in a red box */
4931 scr.drawVerticalLine(gc_foot,
4933 offset, offset + row_ptr->height);
4935 scr.drawVerticalLine(gc_foot,
4936 paperwidth - LYX_PAPER_MARGIN,
4938 offset + row_ptr->height);
4941 if (row_ptr->previous &&
4942 row_ptr->previous->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4943 LyXFont font(LyXFont::ALL_SANE);
4944 font.setSize(LyXFont::SIZE_FOOTNOTE);
4946 int box_x = LYX_PAPER_MARGIN;
4947 box_x += font.textWidth(" wide-tab ", 10);
4949 scr.drawLine(gc_foot,
4952 paperwidth - LYX_PAPER_MARGIN - box_x);
4956 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
4957 row_ptr->par->GetLayout());
4958 firstpar = row_ptr->par->FirstPhysicalPar();
4961 y_bottom = row_ptr->height;
4963 /* is it a first row? */
4964 if (row_ptr->pos == 0
4965 && row_ptr->par == firstpar) {
4967 /* start of appendix? */
4968 if (row_ptr->par->start_of_appendix){
4969 scr.drawLine(gc_math,
4974 /* think about the margins */
4975 if (!row_ptr->previous)
4976 y_top += LYX_PAPER_MARGIN;
4978 if (row_ptr->par->pagebreak_top){ /* draw a top pagebreak */
4979 scr.drawOnOffLine(offset + y_top + 2 * DefaultHeight(),
4981 y_top += 3 * DefaultHeight();
4984 if (row_ptr->par->added_space_top.kind() == VSpace::VFILL) {
4985 /* draw a vfill top */
4986 scr.drawLine(gc_fill,
4988 0, LYX_PAPER_MARGIN);
4989 scr.drawLine(gc_fill,
4990 offset + y_top + 3 * DefaultHeight(),
4991 0, LYX_PAPER_MARGIN);
4992 scr.drawVerticalOnOffLine(LYX_PAPER_MARGIN / 2,
4994 offset + y_top + 3 *
4997 y_top += 3 * DefaultHeight();
5000 /* think about user added space */
5001 y_top += int(row_ptr->par->added_space_top.inPixels());
5003 /* think about the parskip */
5004 /* some parskips VERY EASY IMPLEMENTATION */
5005 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
5006 if (layout.latextype == LATEX_PARAGRAPH
5007 && firstpar->GetDepth() == 0
5008 && firstpar->Previous())
5009 y_top += parameters->getDefSkip().inPixels();
5010 else if (firstpar->Previous()
5011 && textclasslist.Style(parameters->textclass,
5012 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
5013 && firstpar->Previous()->GetDepth() == 0)
5014 // is it right to use defskip here, too? (AS)
5015 y_top += parameters->getDefSkip().inPixels();
5018 if (row_ptr->par->line_top) { /* draw a top line */
5019 y_top += GetFont(row_ptr->par, 0).ascent('x');
5021 scr.drawThickLine(offset + y_top,
5023 y_top += GetFont(row_ptr->par, 0).ascent('x');
5026 /* should we print a label? */
5027 if (layout.labeltype >= LABEL_STATIC
5028 && (layout.labeltype != LABEL_STATIC
5029 || layout.latextype != LATEX_ENVIRONMENT
5030 || row_ptr->par->IsFirstInSequence())) {
5031 font = GetFont(row_ptr->par, -2);
5032 if (!row_ptr->par->GetLabestring().empty()) {
5034 string tmpstring = row_ptr->par->GetLabestring();
5036 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
5037 if (parameters->secnumdepth >= 0){
5038 /* this is special code for the chapter layout. This is printed in
5039 * an extra row and has a pagebreak at the top. */
5040 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue())
5041 + int(layout.parsep) * DefaultHeight();
5042 if (direction == LYX_DIR_RIGHT_TO_LEFT)
5043 tmpx = paperwidth - LeftMargin(row_ptr) -
5044 font.stringWidth(tmpstring);
5045 scr.drawString(font, tmpstring,
5046 offset + row_ptr->baseline
5047 - row_ptr->ascent_of_text - maxdesc,
5051 if (direction == LYX_DIR_LEFT_TO_RIGHT)
5052 tmpx = x - font.stringWidth(layout.labelsep)
5053 - font.stringWidth(tmpstring);
5055 tmpx = paperwidth - LeftMargin(row_ptr)
5056 + font.stringWidth(layout.labelsep);
5057 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
5058 LyXFont font(LyXFont::ALL_SANE);
5059 font.setSize(LyXFont::SIZE_SMALL);
5060 tmpx += font.textWidth("Mwide-figM", 10);
5064 scr.drawString(font, tmpstring,
5065 offset + row_ptr->baseline, int(tmpx));
5068 /* the labels at the top of an environment. More or less for bibliography */
5069 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
5070 layout.labeltype == LABEL_BIBLIO ||
5071 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
5072 if (row_ptr->par->IsFirstInSequence()) {
5073 font = GetFont(row_ptr->par, -2);
5074 if (!row_ptr->par->GetLabestring().empty()) {
5075 string tmpstring = row_ptr->par->GetLabestring();
5077 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue()
5078 + (layout.labelbottomsep * DefaultHeight()));
5081 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
5082 tmpx = ( ((direction == LYX_DIR_LEFT_TO_RIGHT)
5083 ? x : LeftMargin(row_ptr) )
5084 + paperwidth - RightMargin(row_ptr) ) / 2;
5085 tmpx -= (font.stringWidth(tmpstring)/2);
5086 } else if (direction == LYX_DIR_RIGHT_TO_LEFT)
5087 tmpx = paperwidth - LeftMargin(row_ptr) -
5088 font.stringWidth(tmpstring);
5090 scr.drawString(font, tmpstring,
5091 offset + row_ptr->baseline
5092 - row_ptr->ascent_of_text - maxdesc,
5097 if (layout.labeltype == LABEL_BIBLIO) { // ale970302
5098 if (row_ptr->par->bibkey) {
5099 font = GetFont(row_ptr->par, -1);
5100 if (direction == LYX_DIR_LEFT_TO_RIGHT)
5101 tmpx = x - font.stringWidth(layout.labelsep)
5102 - row_ptr->par->bibkey->Width(font);
5104 tmpx = paperwidth - LeftMargin(row_ptr)
5105 + font.stringWidth(layout.labelsep);
5106 row_ptr->par->bibkey->Draw(font, scr,
5107 offset + row_ptr->baseline,
5113 /* is it a last row? */
5114 par = row_ptr->par->LastPhysicalPar();
5115 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
5116 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
5118 /* think about the margins */
5120 y_bottom -= LYX_PAPER_MARGIN;
5122 /* draw a bottom pagebreak */
5123 if (firstpar->pagebreak_bottom) {
5124 scr.drawOnOffLine(offset + y_bottom - 2 *
5127 y_bottom -= 3 * DefaultHeight();
5130 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
5131 /* draw a vfill bottom */
5132 scr.drawLine(gc_fill,
5133 offset + y_bottom - 3 * DefaultHeight(),
5134 0, LYX_PAPER_MARGIN);
5135 scr.drawLine(gc_fill, offset + y_bottom - 2,
5136 0, LYX_PAPER_MARGIN);
5137 scr.drawVerticalOnOffLine(LYX_PAPER_MARGIN / 2,
5138 offset + y_bottom - 3 * DefaultHeight(),
5139 offset + y_bottom - 2
5141 y_bottom -= 3* DefaultHeight();
5144 /* think about user added space */
5145 y_bottom -= int(firstpar->added_space_bottom.inPixels());
5147 if (firstpar->line_bottom) {
5148 /* draw a bottom line */
5149 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
5151 scr.drawThickLine(offset + y_bottom,
5153 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
5157 /* draw the text in the pixmap */
5158 pos_end = RowLast(row_ptr);
5160 vpos = row_ptr->pos;
5161 /* table stuff -- begin*/
5162 if (row_ptr->par->table) {
5164 int cell = NumberOfCell(row_ptr->par, row_ptr->pos);
5166 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
5168 while (vpos <= pos_end) {
5169 pos = vis2log(vpos);
5170 if (row_ptr->par->IsNewline(pos)) {
5172 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
5173 /* draw the table lines, still very simple */
5174 on_off = !row_ptr->par->table->TopLine(cell);
5176 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
5177 !row_ptr->par->table->IsContRow(cell))
5178 scr.drawTableLine(offset + row_ptr->baseline -
5179 row_ptr->ascent_of_text,
5180 int(x_old), int(x - x_old), on_off);
5181 on_off = !row_ptr->par->table->BottomLine(cell);
5182 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
5183 row_ptr->par->table->VeryLastRow(cell))
5184 scr.drawTableLine(offset + y_bottom - 1,
5185 int(x_old), int(x - x_old), on_off);
5186 on_off = !row_ptr->par->table->LeftLine(cell);
5188 scr.drawVerticalTableLine(int(x_old),
5189 offset + row_ptr->baseline -
5190 row_ptr->ascent_of_text,
5191 offset + y_bottom - 1,
5193 on_off = !row_ptr->par->table->RightLine(cell);
5195 scr.drawVerticalTableLine(int(x) -
5196 row_ptr->par->table->AdditionalWidth(cell),
5197 offset + row_ptr->baseline -
5198 row_ptr->ascent_of_text,
5199 offset + y_bottom - 1,
5202 /* take care about the alignment and other spaces */
5204 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
5205 if (row_ptr->par->table->IsFirstCell(cell))
5206 --cell; // little hack, sorry
5208 } else if (row_ptr->par->IsHfill(pos)) {
5211 scr.drawVerticalLine(gc_fill, int(x),
5212 offset + row_ptr->baseline - DefaultHeight()/2,
5213 offset + row_ptr->baseline);
5217 if (row_ptr->par->IsSeparator(pos)) {
5219 x+= SingleWidth(row_ptr->par, pos);
5220 /* -------> Only draw protected spaces when not in
5221 * free-spacing mode. */
5222 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
5223 scr.drawVerticalLine(gc_fill, int(tmpx),
5224 offset + row_ptr->baseline - 3,
5225 offset + row_ptr->baseline - 1);
5226 scr.drawLine(gc_fill,
5227 offset + row_ptr->baseline - 1,
5230 scr.drawVerticalLine(gc_fill, int(x-2),
5231 offset + row_ptr->baseline - 3,
5232 offset + row_ptr->baseline - 1);
5233 /* what about underbars? */
5234 font = GetFont(row_ptr->par, pos);
5235 if (font.underbar() == LyXFont::ON
5236 && font.latex() != LyXFont::ON) {
5237 scr.drawLine(gc_copy,
5239 row_ptr->baseline + 2,
5246 Draw(row_ptr, vpos, scr, offset, x);
5250 /* do not forget the very last cell. This has no NEWLINE so
5251 * ignored by the code above*/
5252 if (cell == row_ptr->par->table->GetNumberOfCells()-1){
5253 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
5254 on_off = !row_ptr->par->table->TopLine(cell);
5256 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
5257 !row_ptr->par->table->IsContRow(cell))
5259 scr.drawTableLine(offset + row_ptr->baseline -
5260 row_ptr->ascent_of_text,
5261 int(x_old), int(x - x_old), on_off);
5262 on_off = !row_ptr->par->table->BottomLine(cell);
5263 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
5264 row_ptr->par->table->VeryLastRow(cell))
5266 scr.drawTableLine(offset + y_bottom - 1,
5267 int(x_old), int(x - x_old), on_off);
5268 on_off = !row_ptr->par->table->LeftLine(cell);
5270 scr.drawVerticalTableLine(int(x_old),
5271 offset + row_ptr->baseline -
5272 row_ptr->ascent_of_text,
5273 offset + y_bottom - 1,
5275 on_off = !row_ptr->par->table->RightLine(cell);
5277 scr.drawVerticalTableLine(int(x) -
5278 row_ptr->par->table->AdditionalWidth(cell),
5279 offset + row_ptr->baseline -
5280 row_ptr->ascent_of_text,
5281 offset + y_bottom - 1,
5285 /* table stuff -- end*/
5286 LyXParagraph::size_type main_body =
5287 BeginningOfMainBody(row_ptr->par);
5288 if (main_body > 0 &&
5289 (main_body-1 > pos_end ||
5290 !row_ptr->par->IsLineSeparator(main_body-1)))
5293 while (vpos <= pos_end) {
5294 pos = vis2log(vpos);
5295 if (main_body > 0 && pos == main_body-1) {
5296 x += fill_label_hfill
5297 + GetFont(row_ptr->par, -2).stringWidth(layout.labelsep)
5298 - SingleWidth(row_ptr->par, main_body-1);
5301 if (row_ptr->par->IsHfill(pos)) {
5303 scr.drawVerticalLine(gc_fill, int(x),
5304 offset + row_ptr->baseline - DefaultHeight()/2,
5305 offset + row_ptr->baseline);
5306 if (HfillExpansion(row_ptr, pos)) {
5307 if (pos >= main_body) {
5308 scr.drawOnOffLine(offset + row_ptr->baseline -
5314 scr.drawOnOffLine(offset + row_ptr->baseline -
5317 int(fill_label_hfill));
5318 x += fill_label_hfill;
5320 scr.drawVerticalLine(gc_fill, int(x),
5321 offset + row_ptr->baseline -
5323 offset + row_ptr->baseline);
5328 if (row_ptr->par->IsSeparator(pos)) {
5330 x+= SingleWidth(row_ptr->par, pos);
5331 if (pos >= main_body)
5333 /* -------> Only draw protected spaces when not in
5334 * free-spacing mode. */
5335 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
5337 scr.drawVerticalLine(gc_fill, int(tmpx),
5338 offset + row_ptr->baseline - 3,
5339 offset + row_ptr->baseline - 1);
5340 scr.drawLine(gc_fill,
5341 offset + row_ptr->baseline - 1,
5344 scr.drawVerticalLine(gc_fill, int(x-2),
5345 offset + row_ptr->baseline - 3,
5346 offset + row_ptr->baseline - 1);
5347 /* what about underbars? */
5348 font = GetFont(row_ptr->par, pos);
5349 if (font.underbar() == LyXFont::ON
5350 && font.latex() != LyXFont::ON) {
5351 scr.drawLine(gc_copy,
5352 offset + row_ptr->baseline + 2,
5359 Draw(row_ptr, vpos, scr, offset, x);
5363 // check for FAST SELECTION
5364 if (fast_selection || mono_video) {
5367 /* selection code */
5368 if (sel_start_cursor.row == row_ptr && sel_end_cursor.row == row_ptr) {
5369 scr.fillRectangle(gc_select, sel_start_cursor.x, offset,
5370 sel_end_cursor.x - sel_start_cursor.x,
5372 } else if (sel_start_cursor.row == row_ptr) {
5373 scr.fillRectangle(gc_select, sel_start_cursor.x, offset,
5374 paperwidth - sel_start_cursor.x,
5376 } else if (sel_end_cursor.row == row_ptr) {
5377 scr.fillRectangle(gc_select, 0, offset,
5380 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
5381 scr.fillRectangle(gc_select, 0, offset,
5382 paperwidth, row_ptr->height);
5387 // end of FAST SELECTION code
5392 int LyXText::DefaultHeight() const
5394 LyXFont font(LyXFont::ALL_SANE);
5395 return int(font.maxAscent() + font.maxDescent() * 1.5);
5399 /* returns the column near the specified x-coordinate of the row
5400 * x is set to the real beginning of this column */
5401 int LyXText::GetColumnNearX(Row * row, int & x) const
5404 float fill_separator, fill_hfill, fill_label_hfill;
5406 PrepareToPrint(row, tmpx, fill_separator,
5407 fill_hfill, fill_label_hfill);
5409 LyXDirection direction = row->par->getParDirection();
5410 LyXParagraph::size_type vc = row->pos;
5411 LyXParagraph::size_type last = RowLast(row);
5412 LyXParagraph::size_type c;
5414 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
5415 row->par->GetLayout());
5416 /* table stuff -- begin */
5417 if (row->par->table) {
5418 if (row->next && row->next->par == row->par //the last row doesn't need a newline at the end
5419 && row->par->IsNewline(last))
5421 int cell = NumberOfCell(row->par, row->pos);
5424 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
5426 && (c = vis2log(vc)) >= 0
5427 && tmpx + (SingleWidth(row->par, c)/2) <= x
5429 if (row->par->IsNewline(c)) {
5430 if (x_old + row->par->table->WidthOfColumn(cell) <= x){
5431 tmpx = x_old + row->par->table->WidthOfColumn(cell);
5434 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
5439 tmpx += SingleWidth(row->par, c);
5444 /* table stuff -- end*/
5445 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
5446 float last_tmpx = tmpx;
5448 if (main_body > 0 &&
5449 (main_body-1 > last ||
5450 !row->par->IsLineSeparator(main_body-1)))
5453 while (vc <= last && tmpx <= x) {
5456 if (main_body > 0 && c == main_body-1) {
5457 tmpx += fill_label_hfill +
5458 GetFont(row->par, -2).stringWidth(layout.labelsep);
5459 if (row->par->IsLineSeparator(main_body-1))
5460 tmpx -= SingleWidth(row->par, main_body-1);
5463 tmpx += SingleWidth(row->par, c);
5464 if (HfillExpansion(row, c)) {
5468 tmpx += fill_label_hfill;
5470 else if (c >= main_body
5471 && row->par->IsSeparator(c)) {
5472 tmpx+= fill_separator;
5477 if (vc > row->pos && (tmpx+last_tmpx)/2 > x) {
5482 /* make sure that a last space in a row doesnt count */
5483 if (row->pos <= last
5484 && !(!row->next || row->next->par != row->par))
5485 if (direction == LYX_DIR_LEFT_TO_RIGHT && vc > last
5486 && row->par->IsLineSeparator(vis2log(last)) ) {
5488 tmpx -= fill_separator+SingleWidth(row->par, vis2log(last));
5489 } else if (direction == LYX_DIR_RIGHT_TO_LEFT
5491 && row->par->IsLineSeparator(vis2log(row->pos)) ) {
5493 tmpx += fill_separator+SingleWidth(row->par, vis2log(row->pos));
5496 if (row->pos > last) // Row is empty?
5498 else if (vc <= last) {
5500 LyXDirection direction = row->par->getLetterDirection(c);
5501 if (vc > row->pos && row->par->IsLineSeparator(c)
5502 && row->par->getLetterDirection(vis2log(vc - 1)) != direction)
5504 if (direction == LYX_DIR_RIGHT_TO_LEFT)
5507 c = vis2log(last)+1;
5508 if (row->par->getLetterDirection(c - 1) == LYX_DIR_RIGHT_TO_LEFT)
5512 if (!row->par->table && row->pos <= last && c > last
5513 && row->par->IsNewline(last)) {
5514 if (row->par->getLetterDirection(last) == LYX_DIR_LEFT_TO_RIGHT)
5515 tmpx -= SingleWidth(row->par, last);
5517 tmpx += SingleWidth(row->par, last);
5527 /* turn the selection into a new environment. If there is no selection,
5528 * create an empty environment */
5529 void LyXText::InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind)
5531 /* no footnoteenvironment in a footnoteenvironment */
5532 if (cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
5533 WriteAlert(_("Impossible operation"),
5534 _("You can't insert a float in a float!"),
5538 /* no marginpars in minipages */
5539 if (kind == LyXParagraph::MARGIN
5540 && cursor.par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
5541 WriteAlert(_("Impossible operation"),
5542 _("You can't insert a marginpar in a minipage!"),
5547 /* this doesnt make sense, if there is no selection */
5548 bool dummy_selection = false;
5550 sel_start_cursor = cursor; /* dummy selection */
5551 sel_end_cursor = cursor;
5552 dummy_selection = true;
5555 LyXParagraph *tmppar;
5557 if (sel_start_cursor.par->table || sel_end_cursor.par->table){
5558 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
5562 /* a test to make sure there is not already a footnote
5563 * in the selection. */
5565 tmppar = sel_start_cursor.par->ParFromPos(sel_start_cursor.pos);
5567 while (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos) &&
5568 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
5569 tmppar = tmppar->next;
5571 if (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)
5572 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
5573 WriteAlert(_("Impossible operation"),
5574 _("Float would include float!"),
5579 /* ok we have a selection. This is always between sel_start_cursor
5580 * and sel_end cursor */
5582 SetUndo(Undo::FINISH,
5583 sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous,
5584 sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)->next);
5586 if (sel_end_cursor.pos > 0
5587 && sel_end_cursor.par->IsLineSeparator(sel_end_cursor.pos - 1))
5588 sel_end_cursor.pos--; /* please break before a space at
5590 if (sel_start_cursor.par == sel_end_cursor.par
5591 && sel_start_cursor.pos > sel_end_cursor.pos)
5592 sel_start_cursor.pos--;
5594 sel_end_cursor.par->BreakParagraphConservative(sel_end_cursor.pos);
5596 sel_end_cursor.par = sel_end_cursor.par->Next();
5597 sel_end_cursor.pos = 0;
5599 // don't forget to insert a dummy layout paragraph if necessary
5600 if (sel_start_cursor.par->GetLayout() != sel_end_cursor.par->layout){
5601 sel_end_cursor.par->BreakParagraphConservative(0);
5602 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
5603 sel_end_cursor.par = sel_end_cursor.par->next;
5606 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
5608 cursor = sel_end_cursor;
5610 /* please break behind a space, if there is one. The space should
5612 if (sel_start_cursor.pos > 0
5613 && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1))
5614 sel_start_cursor.pos--;
5615 if (sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) {
5616 sel_start_cursor.par->Erase(sel_start_cursor.pos);
5619 sel_start_cursor.par->BreakParagraphConservative(sel_start_cursor.pos);
5620 tmppar = sel_start_cursor.par->Next();
5622 if (dummy_selection) {
5624 if (kind == LyXParagraph::TAB
5625 || kind == LyXParagraph::FIG
5626 || kind == LyXParagraph::WIDE_TAB
5627 || kind == LyXParagraph::WIDE_FIG
5628 || kind == LyXParagraph::ALGORITHM) {
5629 int lay = textclasslist.NumberOfLayout(parameters->textclass,
5631 if (lay == -1) // layout not found
5632 // use default layout "Standard" (0)
5634 tmppar->SetLayout(lay);
5638 if (sel_start_cursor.pos > 0) {
5639 /* the footnote-environment should begin with a standard layout.
5640 * Imagine you insert a footnote within an enumeration, you
5641 * certainly do not want an enumerated footnote! */
5645 /* this is a exception the user would sometimes expect, I hope */
5646 sel_start_cursor.par->Clear();
5650 while (tmppar != sel_end_cursor.par) {
5651 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
5652 tmppar->footnotekind = kind;
5653 tmppar = tmppar->Next();
5656 RedoParagraphs(sel_start_cursor, sel_end_cursor.par->Next());
5658 SetCursor(sel_start_cursor.par->Next(), 0);
5664 // returns pointer to a specified row
5665 Row * LyXText::GetRow(LyXParagraph * par,
5666 LyXParagraph::size_type pos, long & y) const
5671 if (par == currentrow->par || par == currentrow->par->Previous()) {
5672 // do not dereference par, it may have been deleted
5673 // already! (Matthias)
5674 while (currentrow->previous && currentrow->previous->par != par) {
5675 currentrow = currentrow->previous;
5676 currentrow_y -= currentrow->height;
5678 while (currentrow->previous && currentrow->previous->par == par) {
5679 currentrow = currentrow->previous;
5680 currentrow_y -= currentrow->height;
5683 tmprow = currentrow;
5685 // find the first row of the specified paragraph
5686 while (tmprow->next && (tmprow->par != par)) {
5687 y += tmprow->height;
5688 tmprow = tmprow->next;
5691 if (tmprow->par == par){
5692 // now find the wanted row
5693 while (tmprow->pos < pos && tmprow->next && tmprow->next->par == par &&
5694 tmprow->next->pos <= pos) {
5695 y += tmprow->height;
5696 tmprow = tmprow->next;
5698 currentrow = tmprow;
5705 // find the first row of the specified paragraph
5706 while (tmprow->next && (tmprow->par != par)) {
5707 y += tmprow->height;
5708 tmprow = tmprow->next;
5711 // now find the wanted row
5712 while (tmprow->pos < pos && tmprow->next && tmprow->next->par == par &&
5713 tmprow->next->pos <= pos) {
5714 y += tmprow->height;
5715 tmprow = tmprow->next;
5718 currentrow = tmprow;