1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * ====================================================== */
16 #pragma implementation "table.h"
20 #include "lyxparagraph.h"
22 #include "support/textutils.h"
23 #include "lyx_gui_misc.h"
26 #include "bufferparams.h"
28 #include "lyxscreen.h"
29 #include "minibuffer.h"
39 static const int LYX_PAPER_MARGIN = 20;
41 extern int mono_video;
42 extern int reverse_video;
43 extern int fast_selection;
44 extern BufferView * current_view;
49 extern int bibitemMaxWidth(Painter &, LyXFont const &);
51 extern int bibitemMaxWidth(LyXFont const &);
54 #define FIX_DOUBLE_SPACE 1
56 int LyXText::SingleWidth(LyXParagraph * par,
57 LyXParagraph::size_type pos) const
59 char c = par->GetChar(pos);
60 return SingleWidth(par, pos, c);
65 int LyXText::SingleWidth(LyXParagraph * par,
66 LyXParagraph::size_type pos, char c) const
68 LyXFont font = GetFont(par, pos);
70 // The most common case is handled first (Asger)
74 } else if (IsHfillChar(c)) {
75 return 3; /* Because of the representation
76 * as vertical lines */
77 } else if (c == LyXParagraph::META_FOOTNOTE ||
78 c == LyXParagraph::META_MARGIN ||
79 c == LyXParagraph::META_FIG ||
80 c == LyXParagraph::META_TAB ||
81 c == LyXParagraph::META_WIDE_FIG ||
82 c == LyXParagraph::META_WIDE_TAB ||
83 c == LyXParagraph::META_ALGORITHM) {
86 case LyXParagraph::META_MARGIN:
89 case LyXParagraph::META_FIG:
92 case LyXParagraph::META_TAB:
95 case LyXParagraph::META_ALGORITHM:
98 case LyXParagraph::META_WIDE_FIG:
101 case LyXParagraph::META_WIDE_TAB:
104 case LyXParagraph::META_FOOTNOTE:
110 return font.stringWidth(fs);
111 } else if (c == LyXParagraph::META_INSET) {
112 Inset * tmpinset= par->GetInset(pos);
114 return par->GetInset(pos)->width(owner_->painter(),
119 } else if (IsSeparatorChar(c))
121 else if (IsNewlineChar(c))
123 return font.width(c);
126 int LyXText::SingleWidth(LyXParagraph * par,
127 LyXParagraph::size_type pos, char c) const
129 LyXFont font = GetFont(par, pos);
131 // The most common case is handled first (Asger)
132 if (IsPrintable(c)) {
133 return font.width(c);
135 } else if (IsHfillChar(c)) {
136 return 3; /* Because of the representation
137 * as vertical lines */
139 } else if (c == LyXParagraph::META_FOOTNOTE ||
140 c == LyXParagraph::META_MARGIN ||
141 c == LyXParagraph::META_FIG ||
142 c == LyXParagraph::META_TAB ||
143 c == LyXParagraph::META_WIDE_FIG ||
144 c == LyXParagraph::META_WIDE_TAB ||
145 c == LyXParagraph::META_ALGORITHM)
149 case LyXParagraph::META_MARGIN:
152 case LyXParagraph::META_FIG:
155 case LyXParagraph::META_TAB:
158 case LyXParagraph::META_ALGORITHM:
161 case LyXParagraph::META_WIDE_FIG:
164 case LyXParagraph::META_WIDE_TAB:
167 case LyXParagraph::META_FOOTNOTE:
173 return font.stringWidth(fs);
176 else if (c == LyXParagraph::META_INSET) {
177 Inset *tmpinset= par->GetInset(pos);
179 return par->GetInset(pos)->Width(font);
183 } else if (IsSeparatorChar(c))
185 else if (IsNewlineChar(c))
187 return font.width(c);
192 // Returns the paragraph position of the last character in the specified row
193 LyXParagraph::size_type LyXText::RowLast(Row const * row) const
196 return row->par->Last() - 1;
197 else if (row->next->par != row->par)
198 return row->par->Last() - 1;
200 return row->next->pos - 1;
204 LyXDirection BufferParams::getDocumentDirection() const
206 return (lyxrc->rtl_support && language == "hebrew")
207 ? LYX_DIR_RIGHT_TO_LEFT : LYX_DIR_LEFT_TO_RIGHT;
210 LyXDirection LyXParagraph::getParDirection() const
212 if (!lyxrc->rtl_support || table)
213 return LYX_DIR_LEFT_TO_RIGHT;
216 return (getFont(0).direction() == LyXFont::RTL_DIR)
217 ? LYX_DIR_RIGHT_TO_LEFT : LYX_DIR_LEFT_TO_RIGHT;
219 return current_view->buffer()->params.getDocumentDirection();
222 LyXDirection LyXFont::getFontDirection() const
224 if (lyxrc->rtl_support
225 && direction() == LyXFont::RTL_DIR
226 && latex() != LyXFont::ON)
227 return LYX_DIR_RIGHT_TO_LEFT;
229 return LYX_DIR_LEFT_TO_RIGHT;
233 LyXParagraph::getLetterDirection(LyXParagraph::size_type pos) const
235 if (!lyxrc->rtl_support)
236 return LYX_DIR_LEFT_TO_RIGHT;
238 LyXDirection direction = getFont(pos).getFontDirection();
239 if (IsLineSeparator(pos) && 0 < pos && pos < Last() - 1
240 && !IsLineSeparator(pos + 1)
241 && !(table && IsNewline(pos + 1))
242 && (getFont(pos - 1).getFontDirection() != direction
243 || getFont(pos + 1).getFontDirection() != direction))
244 return getParDirection();
250 void LyXText::ComputeBidiTables(Row * row) const
253 if (!lyxrc->rtl_support) {
257 LyXParagraph::size_type last = RowLast(row);
258 bidi_start = row->pos;
260 if (bidi_start > last) {
265 if (last + 2 - bidi_start >
266 static_cast<LyXParagraph::size_type>(log2vis_list.size())) {
267 LyXParagraph::size_type new_size =
268 (last + 2 - bidi_start < 500) ?
269 500 : 2 * (last + 2 - bidi_start);
270 log2vis_list.resize(new_size);
271 vis2log_list.resize(new_size);
274 vis2log_list[last + 1 - bidi_start] = -1;
275 log2vis_list[last + 1 - bidi_start] = -1;
277 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
278 if (main_body > 0 && row->pos < main_body - 1 && main_body - 1 <= last
279 && row->par->IsLineSeparator(main_body - 1)) {
280 // This is needed in case there is a direction change in
281 // the label which is continued into the main body
282 if (row->par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) {
283 ComputeBidiTablesFromTo(row, bidi_start,
285 log2vis_list[main_body - 1 - bidi_start] =
287 vis2log_list[main_body - 1 - bidi_start] =
289 if (main_body <= last)
290 ComputeBidiTablesFromTo(row,
293 ComputeBidiTablesFromTo(row, bidi_start,
295 last - main_body + 2);
296 log2vis_list[main_body - 1 - bidi_start] =
297 last - main_body + 1 + bidi_start;
298 vis2log_list[last - main_body + 1 - bidi_start] =
300 if (main_body <= last)
301 ComputeBidiTablesFromTo(row, main_body,
305 ComputeBidiTablesFromTo(row, bidi_start, last, 0);
309 void LyXText::ComputeBidiTablesFromTo(Row * row,
310 LyXParagraph::size_type from,
311 LyXParagraph::size_type to,
312 LyXParagraph::size_type offset) const
314 LyXParagraph::size_type vpos, old_lpos, stack[2];
315 LyXDirection par_direction = row->par->getParDirection();
316 LyXDirection direction = par_direction;
317 LyXParagraph::size_type lpos = from;
321 if (row->par->getLetterDirection(lpos) == direction) {
322 log2vis_list[lpos - bidi_start] = direction;
326 (level == 1 && direction == LYX_DIR_RIGHT_TO_LEFT
327 && row->par->getFont(lpos).direction() ==
329 && row->par->getFont(lpos).latex() ==
331 // The last check is needed when the
333 stack[level++] = lpos;
335 old_lpos = stack[--level];
336 log2vis_list[old_lpos - bidi_start] =
337 log2vis_list[lpos - bidi_start] =
338 (old_lpos - lpos) * direction;
341 direction = static_cast<LyXDirection>(-direction);
346 old_lpos = stack[--level];
347 log2vis_list[old_lpos - bidi_start] =
348 (old_lpos - (to + 1)) * direction;
349 direction = static_cast<LyXDirection>(-direction);
352 vpos = (par_direction == LYX_DIR_LEFT_TO_RIGHT)
355 for (lpos = from; lpos <= to; ++lpos) {
356 vpos += log2vis_list[lpos - bidi_start];
357 vis2log_list[vpos - bidi_start] = lpos;
358 log2vis_list[lpos - bidi_start] = vpos;
364 void LyXText::draw(Row const * row,
365 LyXParagraph::size_type & vpos,
366 int offset, float & x)
368 Painter & pain = owner_->painter();
370 LyXParagraph::size_type pos = vis2log(vpos);
371 char c = row->par->GetChar(pos);
373 if (IsNewlineChar(c)) {
375 // Draw end-of-line marker
376 LyXFont font = GetFont(row->par, pos);
377 int wid = font.width('n');
378 int asc = font.maxAscent();
379 int y = offset + row->baseline;
383 if (row->par->getLetterDirection(pos) == LYX_DIR_LEFT_TO_RIGHT) {
384 xp[0] = int(x + wid * 0.375);
385 yp[0] = int(y - 0.875 * asc * 0.75);
388 yp[1] = int(y - 0.500 * asc * 0.75);
390 xp[2] = int(x + wid * 0.375);
391 yp[2] = int(y - 0.125 * asc * 0.75);
393 pain.lines(xp, yp, 3, LColor::eolmarker);
396 yp[0] = int(y - 0.500 * asc * 0.75);
398 xp[1] = int(x + wid);
399 yp[1] = int(y - 0.500 * asc * 0.75);
401 xp[2] = int(x + wid);
402 yp[2] = int(y - asc * 0.75);
404 pain.lines(xp, yp, 3, LColor::eolmarker);
406 xp[0] = int(x + wid * 0.625);
407 yp[0] = int(y - 0.875 * asc * 0.75);
409 xp[1] = int(x + wid);
410 yp[1] = int(y - 0.500 * asc * 0.75);
412 xp[2] = int(x + wid * 0.625);
413 yp[2] = int(y - 0.125 * asc * 0.75);
415 pain.lines(xp, yp, 3, LColor::eolmarker);
417 xp[0] = int(x + wid);
418 yp[0] = int(y - 0.500 * asc * 0.75);
421 yp[1] = int(y - 0.500 * asc * 0.75);
424 yp[2] = int(y - asc * 0.75);
426 pain.lines(xp, yp, 3, LColor::eolmarker);
431 if (row->par->getLetterDirection(pos) == LYX_DIR_LEFT_TO_RIGHT) {
432 p[0].x = int(x + wid*0.375); p[0].y = int(y - 0.875*asc*0.75);
433 p[1].x = int(x); p[1].y = int(y - 0.500*asc*0.75);
434 p[2].x = int(x + wid*0.375); p[2].y = int(y - 0.125*asc*0.75);
435 scr.drawLines(::getGC(gc_new_line), p, 3);
437 p[0].x = int(x); p[0].y = int(y - 0.500*asc*0.75);
438 p[1].x = int(x + wid); p[1].y = int(y - 0.500*asc*0.75);
439 p[2].x = int(x + wid); p[2].y = int(y - asc*0.75);
440 scr.drawLines(::getGC(gc_new_line), p, 3);
442 p[0].x = int(x + wid*0.625); p[0].y = int(y - 0.875*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*0.625); p[2].y = int(y - 0.125*asc*0.75);
445 scr.drawLines(::getGC(gc_new_line), p, 3);
447 p[0].x = int(x + wid); p[0].y = int(y - 0.500*asc*0.75);
448 p[1].x = int(x); p[1].y = int(y - 0.500*asc*0.75);
449 p[2].x = int(x); p[2].y = int(y - asc*0.75);
450 scr.drawLines(::getGC(gc_new_line), p, 3);
457 LyXFont font = GetFont(row->par, pos);
458 LyXFont font2 = font;
460 if (c == LyXParagraph::META_FOOTNOTE
461 || c == LyXParagraph::META_MARGIN
462 || c == LyXParagraph::META_FIG
463 || c == LyXParagraph::META_TAB
464 || c == LyXParagraph::META_WIDE_FIG
465 || c == LyXParagraph::META_WIDE_TAB
466 || c == LyXParagraph::META_ALGORITHM) {
469 case LyXParagraph::META_MARGIN:
471 // Draw a sign at the left margin!
473 .text((LYX_PAPER_MARGIN - font.width('!'))/2,
474 offset + row->baseline, "!", 1, font);
476 case LyXParagraph::META_FIG:
479 case LyXParagraph::META_TAB:
482 case LyXParagraph::META_ALGORITHM:
485 case LyXParagraph::META_WIDE_FIG:
488 case LyXParagraph::META_WIDE_TAB:
491 case LyXParagraph::META_FOOTNOTE:
498 // calculate the position of the footnotemark
499 int y = (row->baseline - font2.maxAscent()
502 font.setColor(LColor::footnote);
506 // draw it and set new x position
508 pain.text(int(x), offset + y, fs, font);
509 x += pain.width(fs, font);
510 pain.line(int(tmpx), offset + row->baseline,
511 int(x), offset + row->baseline,
517 } else if (c == LyXParagraph::META_INSET) {
518 Inset * tmpinset = row->par->GetInset(pos);
520 tmpinset->draw(owner_->painter(), font,
521 offset + row->baseline, x);
526 /* usual characters, no insets */
528 // Collect character that we can draw in one command
530 // This is dirty, but fast. Notice that it will never be too small.
531 // For the record, I'll note that Microsoft Word has a limit
532 // of 768 here. We have none :-) (Asger)
533 // Ok. I am the first to admit that the use of std::string will be
534 // a tiny bit slower than using a POD char array. However, I claim
535 // that this slowdown is so small that it is close to inperceptive.
536 // So IMHO we should go with the easier and clearer implementation.
537 // And even if 1024 is a large number here it might overflow, string
538 // will only overflow if the machine is out of memory...
539 static string textstring;
543 LyXParagraph::size_type last = RowLast(row);
545 while (vpos <= last &&
546 (pos = vis2log(vpos)) >= 0
547 && static_cast<unsigned char>(c = row->par->GetChar(pos)) > ' '
548 && font2 == GetFont(row->par, pos)) {
555 // If monochrome and LaTeX mode, provide reverse background
557 font.latex() == LyXFont::ON) {
558 int a = font.maxAscent();
559 int d = font.maxDescent();
560 scr.fillRectangle(gc_copy, int(tmpx),
561 offset + row->baseline - a,
562 font.textWidth(textstring.c_str(),
563 textstring.length()), a + d);
567 // Draw text and set the new x position
568 pain.text(int(x), offset + row->baseline, textstring, font);
569 x += pain.width(textstring, font);
571 // what about underbars?
572 if (font.underbar() == LyXFont::ON && font.latex() != LyXFont::ON) {
573 pain.line(tmpx, offset + row->baseline + 2,
574 x, offset + row->baseline + 2);
578 // If we want ulem.sty support, drawing
579 // routines should go here. (Asger)
580 // Why shouldn't LyXFont::drawText handle it internally?
583 void LyXText::Draw(Row const * row, LyXParagraph::size_type & vpos,
584 LyXScreen & scr, int offset, float & x)
586 LyXParagraph::size_type pos = vis2log(vpos);
587 char c = row->par->GetChar(pos);
589 if (IsNewlineChar(c)) {
591 // Draw end-of-line marker
593 LyXFont font = GetFont(row->par, pos);
594 int asc = font.maxAscent();
595 int wid = font.width('n');
596 int y = (offset + row->baseline);
598 if (row->par->getLetterDirection(pos) == LYX_DIR_LEFT_TO_RIGHT) {
599 p[0].x = int(x + wid*0.375); p[0].y = int(y - 0.875*asc*0.75);
600 p[1].x = int(x); p[1].y = int(y - 0.500*asc*0.75);
601 p[2].x = int(x + wid*0.375); p[2].y = int(y - 0.125*asc*0.75);
602 scr.drawLines(::getGC(gc_new_line), p, 3);
604 p[0].x = int(x); p[0].y = int(y - 0.500*asc*0.75);
605 p[1].x = int(x + wid); p[1].y = int(y - 0.500*asc*0.75);
606 p[2].x = int(x + wid); p[2].y = int(y - asc*0.75);
607 scr.drawLines(::getGC(gc_new_line), p, 3);
609 p[0].x = int(x + wid*0.625); p[0].y = int(y - 0.875*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*0.625); p[2].y = int(y - 0.125*asc*0.75);
612 scr.drawLines(::getGC(gc_new_line), p, 3);
614 p[0].x = int(x + wid); p[0].y = int(y - 0.500*asc*0.75);
615 p[1].x = int(x); p[1].y = int(y - 0.500*asc*0.75);
616 p[2].x = int(x); p[2].y = int(y - asc*0.75);
617 scr.drawLines(::getGC(gc_new_line), p, 3);
623 LyXFont font = GetFont(row->par, pos);
624 LyXFont font2 = font;
626 if (c == LyXParagraph::META_FOOTNOTE
627 || c == LyXParagraph::META_MARGIN
628 || c == LyXParagraph::META_FIG
629 || c == LyXParagraph::META_TAB
630 || c == LyXParagraph::META_WIDE_FIG
631 || c == LyXParagraph::META_WIDE_TAB
632 || c == LyXParagraph::META_ALGORITHM) {
635 case LyXParagraph::META_MARGIN:
637 // Draw a sign at the left margin!
638 scr.drawText(font, "!", 1, offset + row->baseline,
639 (LYX_PAPER_MARGIN - font.width('!'))/2);
641 case LyXParagraph::META_FIG:
644 case LyXParagraph::META_TAB:
647 case LyXParagraph::META_ALGORITHM:
650 case LyXParagraph::META_WIDE_FIG:
653 case LyXParagraph::META_WIDE_TAB:
656 case LyXParagraph::META_FOOTNOTE:
663 // calculate the position of the footnotemark
664 int y = (row->baseline - font2.maxAscent()
668 font.setColor(LColor::footnote);
670 font.setColor(LyXFont::RED);
675 // draw it and set new x position
676 x += scr.drawString(font, fs, offset + y, int(x));
678 scr.drawLine(gc_foot, offset + row->baseline,
679 int(tmpx), int(x - tmpx));
683 } else if (c == LyXParagraph::META_INSET) {
684 Inset * tmpinset = row->par->GetInset(pos);
686 tmpinset->Draw(font, scr, offset + row->baseline, x);
691 /* usual characters, no insets */
693 // Collect character that we can draw in one command
695 // This is dirty, but fast. Notice that it will never be too small.
696 // For the record, I'll note that Microsoft Word has a limit
697 // of 768 here. We have none :-) (Asger)
698 // Ok. I am the first to admit that the use of std::string will be
699 // a tiny bit slower than using a POD char array. However, I claim
700 // that this slowdown is so small that it is close to inperceptive.
701 // So IMHO we should go with the easier and clearer implementation.
702 // And even if 1024 is a large number here it might overflow, string
703 // will only overflow if the machine is out of memory...
704 static string textstring;
708 LyXParagraph::size_type last = RowLast(row);
710 while (vpos <= last &&
711 (pos = vis2log(vpos)) >= 0
712 && static_cast<unsigned char>(c = row->par->GetChar(pos)) > ' '
713 && font2 == GetFont(row->par, pos)) {
719 // If monochrome and LaTeX mode, provide reverse background
721 font.latex() == LyXFont::ON) {
722 int a = font.maxAscent();
723 int d = font.maxDescent();
724 scr.fillRectangle(gc_copy, int(tmpx),
725 offset + row->baseline - a,
726 font.textWidth(textstring.c_str(),
727 textstring.length()), a + d);
730 // Draw text and set the new x position
731 x += scr.drawText(font, textstring.c_str(), textstring.length(),
732 offset + row->baseline,
735 // what about underbars?
736 if (font.underbar() == LyXFont::ON && font.latex() != LyXFont::ON) {
737 scr.drawLine(gc_copy, offset + row->baseline + 2,
738 int(tmpx), int(x - tmpx));
741 // If we want ulem.sty support, drawing
742 // routines should go here. (Asger)
743 // Why shouldn't LyXFont::drawText handle it internally?
748 // Returns the left beginning of the text.
749 // This information cannot be taken from the layouts-objekt, because in
750 // LaTeX the beginning of the text fits in some cases (for example sections)
751 // exactly the label-width.
752 int LyXText::LeftMargin(Row const * row) const
754 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
755 row->par->GetLayout());
757 string parindent = layout.parindent;
759 /* table stuff -- begin */
762 /* table stuff -- end */
764 int x = LYX_PAPER_MARGIN;
766 x += textclasslist.TextClass(parameters->textclass)
768 .signedStringWidth(textclasslist
769 .TextClass(parameters->textclass)
772 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
773 LyXFont font(LyXFont::ALL_SANE);
774 font.setSize(LyXFont::SIZE_SMALL);
775 x += font.textWidth("Mwide-figM", 10) + LYX_PAPER_MARGIN/2;
778 // this is the way, LyX handles the LaTeX-Environments.
779 // I have had this idea very late, so it seems to be a
780 // later added hack and this is true
781 if (!row->par->GetDepth()) {
782 if (!row->par->GetLayout()) {
783 // find the previous same level paragraph
784 if (row->par->FirstPhysicalPar()->Previous()) {
785 LyXParagraph * newpar = row->par
786 ->DepthHook(row->par->GetDepth());
788 textclasslist.Style(parameters->textclass,
795 // find the next level paragraph
797 LyXParagraph * newpar = row->par->DepthHook(row->par->GetDepth()-1);
799 // make a corresponding row. Needed to call LeftMargin()
801 // check wether it is a sufficent paragraph
802 if (newpar && newpar->footnoteflag == row->par->footnoteflag
804 .Style(parameters->textclass,
805 newpar->GetLayout()).isEnvironment()) {
807 dummyrow.par = newpar;
808 dummyrow.pos = newpar->Last();
809 x = LeftMargin(&dummyrow);
811 // this is no longer an error, because this function
812 // is used to clear impossible depths after changing
813 // a layout. Since there is always a redo,
814 // LeftMargin() is always called
815 row->par->FirstPhysicalPar()->depth = 0;
818 if (newpar && !row->par->GetLayout()) {
819 if (newpar->FirstPhysicalPar()->noindent)
822 parindent = textclasslist
823 .Style(parameters->textclass,
824 newpar->GetLayout()).parindent;
829 LyXFont labelfont = GetFont(row->par, -2);
830 switch (layout.margintype) {
832 if (!layout.leftmargin.empty()) {
834 .TextClass(parameters->textclass)
836 .signedStringWidth(layout.leftmargin);
838 if (!row->par->GetLabestring().empty()) {
839 x += labelfont.signedStringWidth(layout.labelindent);
840 x += labelfont.stringWidth(row->par->GetLabestring());
841 x += labelfont.stringWidth(layout.labelsep);
845 x += labelfont.signedStringWidth(layout.labelindent);
846 if (row->pos >= BeginningOfMainBody(row->par)) {
847 if (!row->par->GetLabelWidthString().empty()) {
849 .stringWidth(row->par
850 ->GetLabelWidthString());
851 x += labelfont.stringWidth(layout.labelsep);
856 x += textclasslist.TextClass(parameters->textclass)
857 .defaultfont().signedStringWidth(layout.leftmargin) * 4
858 / (row->par->GetDepth() + 4);
860 case MARGIN_FIRST_DYNAMIC:
861 if (layout.labeltype == LABEL_MANUAL) {
862 if (row->pos >= BeginningOfMainBody(row->par)) {
864 .signedStringWidth(layout.leftmargin);
867 .signedStringWidth(layout.labelindent);
870 // Special case to fix problems with
872 || (layout.labeltype == LABEL_STATIC
873 && layout.latextype == LATEX_ENVIRONMENT
874 && ! row->par->IsFirstInSequence())) {
875 x += labelfont.signedStringWidth(layout.leftmargin);
876 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
877 && layout.labeltype != LABEL_BIBLIO
878 && layout.labeltype !=
879 LABEL_CENTERED_TOP_ENVIRONMENT) {
880 x += labelfont.signedStringWidth(layout.labelindent);
881 x += labelfont.stringWidth(layout.labelsep);
882 x += labelfont.stringWidth(row->par->GetLabestring());
886 case MARGIN_RIGHT_ADDRESS_BOX:
888 // ok, a terrible hack. The left margin depends on the widest
889 // row in this paragraph. Do not care about footnotes, they
890 // are *NOT* allowed in the LaTeX realisation of this layout.
892 // find the first row of this paragraph
893 Row const * tmprow = row;
894 while (tmprow->previous && tmprow->previous->par == row->par)
895 tmprow = tmprow->previous;
897 int minfill = tmprow->fill;
898 while (tmprow->next && tmprow->next->par == row->par) {
899 tmprow = tmprow->next;
900 if (tmprow->fill < minfill)
901 minfill = tmprow->fill;
904 x += textclasslist.TextClass(parameters->textclass)
905 .defaultfont().signedStringWidth(layout.leftmargin);
910 if (row->par->pextra_type == LyXParagraph::PEXTRA_INDENT) {
911 if (!row->par->pextra_widthp.empty()) {
913 atoi(row->par->pextra_widthp.c_str()) / 100;
914 } else if (!row->par->pextra_width.empty()) {
915 int xx = VSpace(row->par->pextra_width).inPixels();
918 xx = paperwidth * 80 / 100;
920 } else { // should not happen
921 LyXFont font(LyXFont::ALL_SANE);
922 x += font.stringWidth("XXXXXX");
927 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
928 align = layout.align;
930 align = row->par->FirstPhysicalPar()->align;
932 // set the correct parindent
934 if ((layout.labeltype == LABEL_NO_LABEL
935 || layout.labeltype == LABEL_TOP_ENVIRONMENT
936 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
937 || (layout.labeltype == LABEL_STATIC
938 && layout.latextype == LATEX_ENVIRONMENT
939 && ! row->par->IsFirstInSequence()))
940 && row->par == row->par->FirstPhysicalPar()
941 && align == LYX_ALIGN_BLOCK
942 && !row->par->noindent
943 && (row->par->layout ||
944 parameters->paragraph_separation ==
945 BufferParams::PARSEP_INDENT))
946 x += textclasslist.TextClass(parameters->textclass)
947 .defaultfont().signedStringWidth(parindent);
949 if (layout.labeltype == LABEL_BIBLIO) {
950 // ale970405 Right width for bibitems
952 x += bibitemMaxWidth(owner_->painter(),
954 .TextClass(parameters
958 x += bibitemMaxWidth(textclasslist
959 .TextClass(parameters
970 int LyXText::RightMargin(Row const * row) const
972 LyXLayout const & layout =
973 textclasslist.Style(parameters->textclass,
974 row->par->GetLayout());
976 int x = LYX_PAPER_MARGIN
978 .TextClass(parameters->textclass)
980 .signedStringWidth(textclasslist
981 .TextClass(parameters->textclass)
984 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
985 x += LYX_PAPER_MARGIN / 2;
988 // this is the way, LyX handles the LaTeX-Environments.
989 // I have had this idea very late, so it seems to be a
990 // later added hack and this is true
991 if (row->par->GetDepth()) {
992 // find the next level paragraph
994 LyXParagraph * newpar = row->par;
997 newpar = newpar->FirstPhysicalPar()->Previous();
999 newpar = newpar->FirstPhysicalPar();
1000 } while (newpar && newpar->GetDepth() >= row->par->GetDepth()
1001 && newpar->footnoteflag == row->par->footnoteflag);
1003 // make a corresponding row. Needed to call LeftMargin()
1005 // check wether it is a sufficent paragraph
1006 if (newpar && newpar->footnoteflag == row->par->footnoteflag
1007 && textclasslist.Style(parameters->textclass,
1008 newpar->GetLayout())
1011 dummyrow.par = newpar;
1013 x = RightMargin(&dummyrow);
1015 // this is no longer an error, because this function
1016 // is used to clear impossible depths after changing
1017 // a layout. Since there is always a redo,
1018 // LeftMargin() is always called
1019 row->par->FirstPhysicalPar()->depth = 0;
1023 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
1024 x += textclasslist.TextClass(parameters->textclass)
1026 .signedStringWidth(layout.rightmargin) * 4
1027 / (row->par->GetDepth() + 4);
1032 int LyXText::LabelEnd (Row const * row) const
1034 if (textclasslist.Style(parameters->textclass,
1035 row->par->GetLayout()).margintype
1039 tmprow.pos = row->par->Last();
1040 return LeftMargin(&tmprow); /* just the beginning
1043 return 0; /* LabelEnd is only needed, if the
1044 layout fills a flushleft
1049 /* table stuff -- begin*/
1050 int LyXText::NumberOfCell(LyXParagraph * par,
1051 LyXParagraph::size_type pos) const
1054 LyXParagraph::size_type tmp_pos = 0;
1055 while (tmp_pos < pos) {
1056 if (par->IsNewline(tmp_pos))
1064 int LyXText::WidthOfCell(LyXParagraph * par,
1065 LyXParagraph::size_type & pos) const
1068 while (pos < par->Last() && !par->IsNewline(pos)) {
1069 w += SingleWidth(par, pos);
1072 if (par->IsNewline(pos))
1078 bool LyXText::HitInTable(Row * row, int x) const
1081 float fill_separator, fill_hfill, fill_label_hfill;
1082 if (!row->par->table)
1084 PrepareToPrint(row, tmpx, fill_separator,
1085 fill_hfill, fill_label_hfill, false);
1086 return (x > tmpx && x < tmpx + row->par->table->WidthOfTable());
1090 bool LyXText::MouseHitInTable(int x, long y) const
1092 Row * row = GetRowNearY(y);
1093 return HitInTable(row, x);
1097 /* table stuff -- end*/
1100 // get the next breakpoint in a given paragraph
1101 LyXParagraph::size_type
1102 LyXText::NextBreakPoint(Row const * row, int width) const
1104 LyXParagraph * par = row->par;
1105 LyXParagraph::size_type pos = row->pos;
1107 /* table stuff -- begin*/
1109 while (pos < par->size()
1110 && (!par->IsNewline(pos)
1111 || !par->table->IsFirstCell(NumberOfCell(par, pos+1)))) {
1112 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
1113 par->GetInset(pos) && par->GetInset(pos)->display()){
1114 par->GetInset(pos)->display(false);
1120 /* table stuff -- end*/
1122 // position of the last possible breakpoint
1123 // -1 isn't a suitable value, but a flag
1124 LyXParagraph::size_type last_separator = -1;
1125 int left_margin = LabelEnd(row);
1126 width -= RightMargin(row);
1128 LyXParagraph::size_type main_body = BeginningOfMainBody(par);
1129 LyXLayout const & layout =
1130 textclasslist.Style(parameters->textclass, par->GetLayout());
1131 LyXParagraph::size_type i = pos;
1133 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1134 /* special code for right address boxes, only newlines count */
1135 while (i < par->Last()) {
1136 if (par->IsNewline(i)) {
1138 i = par->Last() - 1; // this means break
1140 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
1141 par->GetInset(i) && par->GetInset(i)->display()){
1142 par->GetInset(i)->display(false);
1147 // Last position is an invariant
1148 LyXParagraph::size_type const last =
1150 // this is the usual handling
1151 int x = LeftMargin(row);
1152 while (x < width && i < last) {
1153 char c = par->GetChar(i);
1154 if (IsNewlineChar(c)) {
1156 x = width; // this means break
1157 } else if (c == LyXParagraph::META_INSET &&
1158 par->GetInset(i) && par->GetInset(i)->display()){
1159 // check wether a Display() inset is
1160 // valid here. if not, change it to
1162 if (layout.isCommand()
1163 || (layout.labeltype == LABEL_MANUAL
1164 && i < BeginningOfMainBody(par))){
1165 // display istn't allowd
1166 par->GetInset(i)->display(false);
1167 x += SingleWidth(par, i, c);
1169 // inset is display. So break the line here
1173 if (IsLineSeparatorChar(par->GetChar(i+1)))
1176 last_separator = last; // to avoid extra rows
1178 last_separator = i - 1;
1179 x = width; // this means break
1182 if (IsLineSeparatorChar(c))
1184 x += SingleWidth(par, i, c);
1187 if (i == main_body) {
1188 x += GetFont(par, -2).stringWidth(layout.labelsep);
1189 if (par->IsLineSeparator(i - 1))
1190 x-= SingleWidth(par, i - 1);
1191 if (x < left_margin)
1195 // end of paragraph is always a suitable separator
1196 if (i == last && x < width)
1200 // well, if last_separator is still 0, the line isn't breakable.
1201 // don't care and cut simply at the end
1202 if (last_separator < 0) {
1206 // manual labels cannot be broken in LaTeX, do not care
1207 if (main_body && last_separator < main_body)
1208 last_separator = main_body - 1;
1210 return last_separator;
1214 // returns the minimum space a row needs on the screen in pixel
1215 int LyXText::Fill(Row const * row, int paper_width) const
1218 // get the pure distance
1219 LyXParagraph::size_type last = RowLast(row);
1220 /* table stuff -- begin */
1221 if (row->par->table) {
1222 // for tables FILL does calculate the widthes of each cell in
1224 LyXParagraph::size_type pos = row->pos;
1225 int cell = NumberOfCell(row->par, pos);
1228 row->par->table->SetWidthOfCell(cell,
1229 WidthOfCell(row->par,
1232 } while (pos <= last && !row->par->table->IsFirstCell(cell));
1233 // don't forget the very last table cell without characters
1234 if (cell == row->par->table->GetNumberOfCells() - 1)
1235 row->par->table->SetWidthOfCell(cell,
1236 WidthOfCell(row->par,
1239 return 0; /* width of table cannot be returned since
1240 * we cannot guarantee its correct value at
1243 /* table stuff -- end*/
1245 int left_margin = LabelEnd(row);
1247 // if the row ends with newline, this newline will not be relevant
1248 //if (last >= 0 && row->par->IsNewline(last))
1251 // if the row ends with a space, this space will not be relevant
1252 if (last >= 0 && row->par->IsLineSeparator(last))
1255 // special handling of the right address boxes
1256 if (textclasslist.Style(parameters->textclass,
1257 row->par->GetLayout()).margintype
1258 == MARGIN_RIGHT_ADDRESS_BOX) {
1259 int tmpfill = row->fill;
1260 row->fill = 0; // the minfill in MarginLeft()
1261 w = LeftMargin(row);
1262 row->fill = tmpfill;
1264 w = LeftMargin(row);
1266 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
1267 row->par->GetLayout());
1268 LyXParagraph::size_type main_body =
1269 BeginningOfMainBody(row->par);
1270 LyXParagraph::size_type i = row->pos;
1273 if (main_body > 0 && i == main_body) {
1274 w += GetFont(row->par, -2).
1275 stringWidth(layout.labelsep);
1276 if (row->par->IsLineSeparator(i - 1))
1277 w -= SingleWidth(row->par, i - 1);
1278 if (w < left_margin)
1281 w += SingleWidth(row->par, i);
1284 if (main_body > 0 && main_body > last) {
1285 w += GetFont(row->par, -2).stringWidth(layout.labelsep);
1286 if (last >= 0 && row->par->IsLineSeparator(last))
1287 w -= SingleWidth(row->par, last);
1288 if (w < left_margin)
1292 fill = paper_width - w - RightMargin(row);
1297 // returns the minimum space a manual label needs on the screen in pixel
1298 int LyXText::LabelFill(Row const * row) const
1300 LyXParagraph::size_type last = BeginningOfMainBody(row->par) - 1;
1301 // -1 because a label ends either with a space that is in the label,
1302 // or with the beginning of a footnote that is outside the label.
1304 // I don't understand this code in depth, but sometimes "last" is
1305 // less than 0 and this causes a crash. This fix seems to work
1306 // correctly, but I bet the real error is elsewhere. The bug is
1307 // triggered when you have an open footnote in a paragraph
1308 // environment with a manual label. (Asger)
1309 if (last < 0) last = 0;
1311 if (row->par->IsLineSeparator(last)) /* a sepearator at this end
1318 w += SingleWidth(row->par, i);
1323 if (!row->par->labelwidthstring.empty()) {
1324 fill = GetFont(row->par, -2)
1325 .stringWidth(row->par->labelwidthstring) - w;
1335 // returns the number of separators in the specified row. The separator
1336 // on the very last column doesnt count
1337 int LyXText::NumberOfSeparators(Row const * row) const
1339 int last = RowLast(row);
1341 //int main_body = BeginningOfMainBody(row->par);
1342 //if (p < main_body)
1344 // I think this is equivalent to the above. (Lgb)
1345 int p = max(row->pos, BeginningOfMainBody(row->par));
1347 for (; p < last; ++p) {
1348 if (row->par->IsSeparator(p)) {
1356 // returns the number of hfills in the specified row. The LyX-Hfill is
1357 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1358 // ignored. This is *MUCH* more usefull than not to ignore!
1359 int LyXText::NumberOfHfills(Row const * row) const
1361 int last = RowLast(row);
1362 int first = row->pos;
1363 if (first) { /* hfill *DO* count at the beginning
1365 while(first <= last && row->par->IsHfill(first))
1369 //int main_body = BeginningOfMainBody(row->par);
1370 //if (first < main_body)
1371 // first = main_body;
1372 // I think this is equivalent to the above. (Lgb)
1373 first = max(first, BeginningOfMainBody(row->par));
1375 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1376 if (row->par->IsHfill(p)) {
1384 // like NumberOfHfills, but only those in the manual label!
1385 int LyXText::NumberOfLabelHfills(Row const * row) const
1387 LyXParagraph::size_type last = RowLast(row);
1388 LyXParagraph::size_type first = row->pos;
1389 if (first) { /* hfill *DO* count at the beginning
1391 while(first < last && row->par->IsHfill(first))
1394 //LyXParagraph::size_type main_body =
1395 //BeginningOfMainBody(row->par);
1396 //if (last > main_body)
1398 // I think this is eqvialent to the above. (Lgb)
1399 last = min(last, BeginningOfMainBody(row->par));
1401 for (LyXParagraph::size_type p = first;
1402 p < last; ++p) { // last, because the end is ignored!
1403 if (row->par->IsHfill(p)) {
1411 // returns true, if a expansion is needed.
1412 // Rules are given by LaTeX
1413 bool LyXText::HfillExpansion(Row const * row_ptr,
1414 LyXParagraph::size_type pos) const
1416 // by the way, is it a hfill?
1417 if (!row_ptr->par->IsHfill(pos))
1420 // at the end of a row it does not count
1421 if (pos >= RowLast(row_ptr))
1424 // at the beginning of a row it does not count, if it is not
1425 // the first row of a paragaph
1429 // in some labels it does not count
1430 if (textclasslist.Style(parameters->textclass,
1431 row_ptr->par->GetLayout()).margintype
1433 && pos < BeginningOfMainBody(row_ptr->par))
1436 // if there is anything between the first char of the row and
1437 // the sepcified position that is not a newline and not a hfill,
1438 // the hfill will count, otherwise not
1439 LyXParagraph::size_type i = row_ptr->pos;
1440 while (i < pos && (row_ptr->par->IsNewline(i)
1441 || row_ptr->par->IsHfill(i)))
1449 void LyXText::SetHeightOfRow(Row * row_ptr) const
1451 /* get the maximum ascent and the maximum descent */
1453 float layoutasc = 0;
1454 float layoutdesc = 0;
1459 /* this must not happen before the currentrow for clear reasons.
1460 so the trick is just to set the current row onto this row */
1462 GetRow(row_ptr->par, row_ptr->pos, unused_y);
1464 /* ok , let us initialize the maxasc and maxdesc value.
1465 * This depends in LaTeX of the font of the last character
1466 * in the paragraph. The hack below is necessary because
1467 * of the possibility of open footnotes */
1469 /* Correction: only the fontsize count. The other properties
1470 are taken from the layoutfont. Nicer on the screen :) */
1472 LyXParagraph * par = row_ptr->par->LastPhysicalPar();
1473 LyXParagraph * firstpar = row_ptr->par->FirstPhysicalPar();
1475 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
1476 firstpar->GetLayout());
1478 LyXFont font = GetFont(par, par->Last()-1);
1479 LyXFont::FONT_SIZE size = font.size();
1480 font = GetFont(par, -1);
1483 LyXFont labelfont = GetFont(par, -2);
1485 int maxasc = int(font.maxAscent() *
1486 layout.spacing.getValue() *
1487 parameters->spacing.getValue());
1488 int maxdesc = int(font.maxDescent() *
1489 layout.spacing.getValue() *
1490 parameters->spacing.getValue());
1492 int pos_end = RowLast(row_ptr);
1496 // Check if any insets are larger
1497 for (pos = row_ptr->pos; pos <= pos_end; ++pos) {
1498 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_INSET) {
1499 tmpfont = GetFont(row_ptr->par, pos);
1500 tmpinset = row_ptr->par->GetInset(pos);
1502 asc = tmpinset->ascent(owner_->painter(), tmpfont);
1503 desc = tmpinset->descent(owner_->painter(), tmpfont);
1512 // Check if any custom fonts are larger (Asger)
1513 // This is not completely correct, but we can live with the small,
1514 // cosmetic error for now.
1515 LyXFont::FONT_SIZE maxsize = row_ptr->par->HighestFontInRange(row_ptr->pos,
1517 if (maxsize > font.size()) {
1518 font.setSize(maxsize);
1520 asc = font.maxAscent();
1521 desc = font.maxDescent();
1528 /* table stuff -- begin*/
1529 if (row_ptr->par->table){
1530 // stretch the rows a bit
1534 /* table stuff -- end*/
1536 // This is nicer with box insets:
1540 row_ptr->ascent_of_text = maxasc;
1542 /* is it a top line? */
1543 if (row_ptr->pos == 0
1544 && row_ptr->par == firstpar) {
1546 /* some parksips VERY EASY IMPLEMENTATION */
1547 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
1548 if (layout.isParagraph()
1549 && firstpar->GetDepth() == 0
1550 && firstpar->Previous())
1551 maxasc += parameters->getDefSkip().inPixels();
1552 else if (firstpar->Previous()
1553 && textclasslist.Style(parameters->textclass,
1554 firstpar->Previous()->GetLayout()).isParagraph()
1555 && firstpar->Previous()->GetDepth() == 0)
1556 // is it right to use defskip here too? (AS)
1557 maxasc += parameters->getDefSkip().inPixels();
1560 /* the paper margins */
1561 if (!row_ptr->par->previous)
1562 maxasc += LYX_PAPER_MARGIN;
1564 /* add the vertical spaces, that the user added */
1565 if (firstpar->added_space_top.kind() != VSpace::NONE)
1566 maxasc += int(firstpar->added_space_top.inPixels());
1568 /* do not forget the DTP-lines!
1569 * there height depends on the font of the nearest character */
1570 if (firstpar->line_top)
1571 maxasc += 2 * GetFont(firstpar, 0).ascent('x');
1573 /* and now the pagebreaks */
1574 if (firstpar->pagebreak_top)
1575 maxasc += 3 * DefaultHeight();
1577 /* this is special code for the chapter, since the label of this
1578 * layout is printed in an extra row */
1579 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1580 && parameters->secnumdepth>= 0) {
1581 labeladdon = int(labelfont.maxDescent() *
1582 layout.spacing.getValue() *
1583 parameters->spacing.getValue())
1584 + int(labelfont.maxAscent() *
1585 layout.spacing.getValue() *
1586 parameters->spacing.getValue());
1589 /* special code for the top label */
1590 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1591 || layout.labeltype == LABEL_BIBLIO
1592 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1593 && row_ptr->par->IsFirstInSequence()
1594 && !row_ptr->par->GetLabestring().empty()) {
1596 (labelfont.maxAscent() *
1597 layout.spacing.getValue() *
1598 parameters->spacing.getValue())
1599 +(labelfont.maxDescent() *
1600 layout.spacing.getValue() *
1601 parameters->spacing.getValue())
1602 + layout.topsep * DefaultHeight()
1603 + layout.labelbottomsep * DefaultHeight());
1606 /* and now the layout spaces, for example before and after a section,
1607 * or between the items of a itemize or enumerate environment */
1609 if (!firstpar->pagebreak_top) {
1610 LyXParagraph * prev = row_ptr->par->Previous();
1612 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth());
1613 if (prev && prev->GetLayout() == firstpar->GetLayout()
1614 && prev->GetDepth() == firstpar->GetDepth()
1615 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1617 layoutasc = (layout.itemsep * DefaultHeight());
1619 else if (row_ptr->previous) {
1620 tmptop = layout.topsep;
1622 if (row_ptr->previous->par->GetDepth() >= row_ptr->par->GetDepth())
1623 tmptop-= textclasslist.Style(parameters->textclass, row_ptr->previous->par->GetLayout()).bottomsep;
1626 layoutasc = (tmptop * DefaultHeight());
1628 else if (row_ptr->par->line_top){
1629 tmptop = layout.topsep;
1632 layoutasc = (tmptop * DefaultHeight());
1635 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth()-1);
1637 maxasc += int(textclasslist.Style(parameters->textclass,
1638 prev->GetLayout()).parsep * DefaultHeight());
1641 if (firstpar->Previous()
1642 && firstpar->Previous()->GetDepth() == 0
1643 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1646 else if (firstpar->Previous()){
1647 maxasc += int(layout.parsep * DefaultHeight());
1653 /* is it a bottom line? */
1654 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
1655 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
1657 /* the paper margins */
1659 maxdesc += LYX_PAPER_MARGIN;
1661 /* add the vertical spaces, that the user added */
1662 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1663 maxdesc += int(firstpar->added_space_bottom.inPixels());
1665 /* do not forget the DTP-lines!
1666 * there height depends on the font of the nearest character */
1667 if (firstpar->line_bottom)
1668 maxdesc += 2 * (GetFont(par, par->Last()-1).ascent('x'));
1670 /* and now the pagebreaks */
1671 if (firstpar->pagebreak_bottom)
1672 maxdesc += 3 * DefaultHeight();
1674 /* and now the layout spaces, for example before and after a section,
1675 * or between the items of a itemize or enumerate environment */
1676 if (!firstpar->pagebreak_bottom && row_ptr->par->Next()) {
1677 LyXParagraph * nextpar = row_ptr->par->Next();
1678 LyXParagraph * comparepar = row_ptr->par;
1682 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1683 usual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1684 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1685 if (comparepar->GetLayout()!= nextpar->GetLayout()
1686 || nextpar->GetLabelWidthString() !=
1687 comparepar->GetLabelWidthString())
1688 unusual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1690 if (unusual > usual)
1691 layoutdesc = unusual;
1695 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1697 if (comparepar->GetLayout()!= nextpar->GetLayout()
1698 || nextpar->GetLabelWidthString() !=
1699 comparepar->GetLabelWidthString())
1700 layoutdesc = int(textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1705 /* incalculate the layout spaces */
1706 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1707 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1709 /* table stuff -- begin*/
1710 if (row_ptr->par->table){
1711 maxasc += row_ptr->par->table->
1712 AdditionalHeight(NumberOfCell(row_ptr->par, row_ptr->pos));
1714 /* table stuff -- end*/
1716 /* calculate the new height of the text */
1717 height -= row_ptr->height;
1719 row_ptr->height = maxasc + maxdesc + labeladdon;
1720 row_ptr->baseline = maxasc + labeladdon;
1722 height += row_ptr->height;
1725 void LyXText::SetHeightOfRow(Row * row_ptr) const
1727 /* get the maximum ascent and the maximum descent */
1728 int asc, maxasc, desc, maxdesc, pos_end, pos, labeladdon;
1729 float layoutasc = 0;
1730 float layoutdesc = 0;
1735 /* this must not happen before the currentrow for clear reasons.
1736 so the trick is just to set the current row onto this row */
1738 GetRow(row_ptr->par, row_ptr->pos, unused_y);
1740 /* ok , let us initialize the maxasc and maxdesc value.
1741 * This depends in LaTeX of the font of the last character
1742 * in the paragraph. The hack below is necessary because
1743 * of the possibility of open footnotes */
1745 /* Correction: only the fontsize count. The other properties
1746 are taken from the layoutfont. Nicer on the screen :) */
1748 LyXParagraph * par = row_ptr->par->LastPhysicalPar();
1749 LyXParagraph * firstpar = row_ptr->par->FirstPhysicalPar();
1751 LyXLayout const & layout = textclasslist.Style(parameters->textclass, firstpar->GetLayout());
1753 LyXFont font = GetFont(par, par->Last()-1);
1754 LyXFont::FONT_SIZE size = font.size();
1755 font = GetFont(par, -1);
1758 LyXFont labelfont = GetFont(par, -2);
1760 maxasc = int(font.maxAscent() *
1761 layout.spacing.getValue() *
1762 parameters->spacing.getValue());
1763 maxdesc = int(font.maxDescent() *
1764 layout.spacing.getValue() *
1765 parameters->spacing.getValue());
1767 pos_end = RowLast(row_ptr);
1771 // Check if any insets are larger
1772 for (pos = row_ptr->pos; pos <= pos_end; ++pos) {
1773 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_INSET) {
1774 tmpfont = GetFont(row_ptr->par, pos);
1775 tmpinset = row_ptr->par->GetInset(pos);
1777 asc = tmpinset->Ascent(tmpfont);
1778 desc = tmpinset->Descent(tmpfont);
1787 // Check if any custom fonts are larger (Asger)
1788 // This is not completely correct, but we can live with the small,
1789 // cosmetic error for now.
1790 LyXFont::FONT_SIZE maxsize = row_ptr->par->HighestFontInRange(row_ptr->pos,
1792 if (maxsize > font.size()) {
1793 font.setSize(maxsize);
1795 asc = font.maxAscent();
1796 desc = font.maxDescent();
1803 /* table stuff -- begin*/
1804 if (row_ptr->par->table){
1805 // stretch the rows a bit
1809 /* table stuff -- end*/
1811 // This is nicer with box insets:
1815 row_ptr->ascent_of_text = maxasc;
1817 /* is it a top line? */
1818 if (row_ptr->pos == 0
1819 && row_ptr->par == firstpar) {
1821 /* some parksips VERY EASY IMPLEMENTATION */
1822 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
1823 if (layout.isParagraph()
1824 && firstpar->GetDepth() == 0
1825 && firstpar->Previous())
1826 maxasc += parameters->getDefSkip().inPixels();
1827 else if (firstpar->Previous()
1828 && textclasslist.Style(parameters->textclass,
1829 firstpar->Previous()->GetLayout()).isParagraph()
1830 && firstpar->Previous()->GetDepth() == 0)
1831 // is it right to use defskip here too? (AS)
1832 maxasc += parameters->getDefSkip().inPixels();
1835 /* the paper margins */
1836 if (!row_ptr->par->previous)
1837 maxasc += LYX_PAPER_MARGIN;
1839 /* add the vertical spaces, that the user added */
1840 if (firstpar->added_space_top.kind() != VSpace::NONE)
1841 maxasc += int(firstpar->added_space_top.inPixels());
1843 /* do not forget the DTP-lines!
1844 * there height depends on the font of the nearest character */
1845 if (firstpar->line_top)
1846 maxasc += 2 * GetFont(firstpar, 0).ascent('x');
1848 /* and now the pagebreaks */
1849 if (firstpar->pagebreak_top)
1850 maxasc += 3 * DefaultHeight();
1852 /* this is special code for the chapter, since the label of this
1853 * layout is printed in an extra row */
1854 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1855 && parameters->secnumdepth>= 0) {
1856 labeladdon = int(labelfont.maxDescent() *
1857 layout.spacing.getValue() *
1858 parameters->spacing.getValue())
1859 + int(labelfont.maxAscent() *
1860 layout.spacing.getValue() *
1861 parameters->spacing.getValue());
1864 /* special code for the top label */
1865 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1866 || layout.labeltype == LABEL_BIBLIO
1867 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1868 && row_ptr->par->IsFirstInSequence()
1869 && !row_ptr->par->GetLabestring().empty()) {
1871 (labelfont.maxAscent() *
1872 layout.spacing.getValue() *
1873 parameters->spacing.getValue())
1874 +(labelfont.maxDescent() *
1875 layout.spacing.getValue() *
1876 parameters->spacing.getValue())
1877 + layout.topsep * DefaultHeight()
1878 + layout.labelbottomsep * DefaultHeight());
1881 /* and now the layout spaces, for example before and after a section,
1882 * or between the items of a itemize or enumerate environment */
1884 if (!firstpar->pagebreak_top) {
1885 LyXParagraph *prev = row_ptr->par->Previous();
1887 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth());
1888 if (prev && prev->GetLayout() == firstpar->GetLayout()
1889 && prev->GetDepth() == firstpar->GetDepth()
1890 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1892 layoutasc = (layout.itemsep * DefaultHeight());
1894 else if (row_ptr->previous) {
1895 tmptop = layout.topsep;
1897 if (row_ptr->previous->par->GetDepth() >= row_ptr->par->GetDepth())
1898 tmptop-= textclasslist.Style(parameters->textclass, row_ptr->previous->par->GetLayout()).bottomsep;
1901 layoutasc = (tmptop * DefaultHeight());
1903 else if (row_ptr->par->line_top){
1904 tmptop = layout.topsep;
1907 layoutasc = (tmptop * DefaultHeight());
1910 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth()-1);
1912 maxasc += int(textclasslist.Style(parameters->textclass,
1913 prev->GetLayout()).parsep * DefaultHeight());
1916 if (firstpar->Previous()
1917 && firstpar->Previous()->GetDepth() == 0
1918 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1921 else if (firstpar->Previous()){
1922 maxasc += int(layout.parsep * DefaultHeight());
1928 /* is it a bottom line? */
1929 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
1930 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
1932 /* the paper margins */
1934 maxdesc += LYX_PAPER_MARGIN;
1936 /* add the vertical spaces, that the user added */
1937 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1938 maxdesc += int(firstpar->added_space_bottom.inPixels());
1940 /* do not forget the DTP-lines!
1941 * there height depends on the font of the nearest character */
1942 if (firstpar->line_bottom)
1943 maxdesc += 2 * (GetFont(par, par->Last()-1).ascent('x'));
1945 /* and now the pagebreaks */
1946 if (firstpar->pagebreak_bottom)
1947 maxdesc += 3 * DefaultHeight();
1949 /* and now the layout spaces, for example before and after a section,
1950 * or between the items of a itemize or enumerate environment */
1951 if (!firstpar->pagebreak_bottom && row_ptr->par->Next()) {
1952 LyXParagraph *nextpar = row_ptr->par->Next();
1953 LyXParagraph *comparepar = row_ptr->par;
1957 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1958 usual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1959 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1960 if (comparepar->GetLayout()!= nextpar->GetLayout()
1961 || nextpar->GetLabelWidthString() !=
1962 comparepar->GetLabelWidthString())
1963 unusual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1965 if (unusual > usual)
1966 layoutdesc = unusual;
1970 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1972 if (comparepar->GetLayout()!= nextpar->GetLayout()
1973 || nextpar->GetLabelWidthString() !=
1974 comparepar->GetLabelWidthString())
1975 layoutdesc = int(textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1980 /* incalculate the layout spaces */
1981 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1982 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1984 /* table stuff -- begin*/
1985 if (row_ptr->par->table){
1986 maxasc += row_ptr->par->table->
1987 AdditionalHeight(NumberOfCell(row_ptr->par, row_ptr->pos));
1989 /* table stuff -- end*/
1991 /* calculate the new height of the text */
1992 height -= row_ptr->height;
1994 row_ptr->height= maxasc+maxdesc+labeladdon;
1995 row_ptr->baseline= maxasc+labeladdon;
1997 height += row_ptr->height;
2002 /* Appends the implicit specified paragraph behind the specified row,
2003 * start at the implicit given position */
2004 void LyXText::AppendParagraph(Row * row) const
2006 bool not_ready = true;
2008 // The last character position of a paragraph is an invariant so we can
2009 // safely get it here. (Asger)
2010 int lastposition = row->par->Last();
2013 // Get the next breakpoint
2014 int z = NextBreakPoint(row, paperwidth);
2018 // Insert the new row
2019 if (z < lastposition) {
2021 InsertRow(row, row->par, z);
2028 // Set the dimensions of the row
2029 tmprow->fill = Fill(tmprow, paperwidth);
2030 SetHeightOfRow(tmprow);
2032 } while (not_ready);
2036 void LyXText::BreakAgain(Row * row) const
2038 bool not_ready = true;
2041 /* get the next breakpoint */
2042 LyXParagraph::size_type z =
2043 NextBreakPoint(row, paperwidth);
2046 if (z < row->par->Last() ) {
2047 if (!row->next || (row->next && row->next->par != row->par)) {
2050 InsertRow(row, row->par, z);
2057 not_ready = false; // the rest will not change
2063 /* if there are some rows too much, delete them */
2064 /* only if you broke the whole paragraph! */
2065 Row * tmprow2 = row;
2066 while (tmprow2->next && tmprow2->next->par == row->par) {
2067 tmprow2 = tmprow2->next;
2069 while (tmprow2 != row) {
2070 tmprow2 = tmprow2->previous;
2071 RemoveRow(tmprow2->next);
2076 /* set the dimensions of the row */
2077 tmprow->fill = Fill(tmprow, paperwidth);
2078 SetHeightOfRow(tmprow);
2079 } while (not_ready);
2083 /* this is just a little changed version of break again */
2084 void LyXText::BreakAgainOneRow(Row * row)
2086 /* get the next breakpoint */
2087 LyXParagraph::size_type z = NextBreakPoint(row, paperwidth);
2090 if (z < row->par->Last() ) {
2091 if (!row->next || (row->next && row->next->par != row->par)) {
2092 /* insert a new row */
2094 InsertRow(row, row->par, z);
2106 /* if there are some rows too much, delete them */
2107 /* only if you broke the whole paragraph! */
2108 Row * tmprow2 = row;
2109 while (tmprow2->next && tmprow2->next->par == row->par) {
2110 tmprow2 = tmprow2->next;
2112 while (tmprow2 != row) {
2113 tmprow2 = tmprow2->previous;
2114 RemoveRow(tmprow2->next);
2118 /* set the dimensions of the row */
2119 tmprow->fill = Fill(tmprow, paperwidth);
2120 SetHeightOfRow(tmprow);
2124 void LyXText::BreakParagraph(char keep_layout)
2126 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
2127 cursor.par->GetLayout());
2129 /* table stuff -- begin */
2130 if (cursor.par->table) {
2131 // breaking of tables is only allowed at the beginning or the end */
2132 if (cursor.pos && cursor.pos < cursor.par->size() &&
2133 !cursor.par->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par, cursor.pos)))
2134 return; // no breaking of tables allowed
2136 /* table stuff -- end */
2138 // this is only allowed, if the current paragraph is not empty or caption
2139 if ((cursor.par->Last() <= 0 && !cursor.par->IsDummy())
2141 layout.labeltype!= LABEL_SENSITIVE)
2144 SetUndo(Undo::INSERT,
2145 cursor.par->ParFromPos(cursor.pos)->previous,
2146 cursor.par->ParFromPos(cursor.pos)->next);
2148 /* table stuff -- begin */
2149 if (cursor.par->table) {
2150 int cell = NumberOfCell(cursor.par, cursor.pos);
2151 if (cursor.par->table->ShouldBeVeryLastCell(cell))
2152 SetCursor(cursor.par, cursor.par->text.size());
2154 /* table stuff -- end */
2156 // please break always behind a space
2157 if (cursor.pos < cursor.par->Last()
2158 && cursor.par->IsLineSeparator(cursor.pos))
2161 // break the paragraph
2165 keep_layout = layout.isEnvironment();
2166 cursor.par->BreakParagraph(cursor.pos, keep_layout);
2168 /* table stuff -- begin */
2169 if (cursor.par->table){
2170 // the table should stay with the contents
2172 cursor.par->Next()->table = cursor.par->table;
2173 cursor.par->table = 0;
2176 /* table stuff -- end */
2178 // well this is the caption hack since one caption is really enough
2179 if (layout.labeltype == LABEL_SENSITIVE){
2181 cursor.par->SetLayout(0); // set to standard-layout
2183 cursor.par->Next()->SetLayout(0); // set to standard-layout
2186 /* if the cursor is at the beginning of a row without prior newline,
2188 * This touches only the screen-update. Otherwise we would may have
2189 * an empty row on the screen */
2190 if (cursor.pos && !cursor.row->par->IsNewline(cursor.row->pos -1) &&
2191 cursor.row->pos == cursor.pos) {
2195 status = LyXText::NEED_MORE_REFRESH;
2196 refresh_row = cursor.row;
2197 refresh_y = cursor.y - cursor.row->baseline;
2199 // Do not forget the special right address boxes
2200 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
2201 while (refresh_row->previous &&
2202 refresh_row->previous->par == refresh_row->par) {
2203 refresh_row = refresh_row->previous;
2204 refresh_y -= refresh_row->height;
2207 RemoveParagraph(cursor.row);
2209 // set the dimensions of the cursor row
2210 cursor.row->fill = Fill(cursor.row, paperwidth);
2212 SetHeightOfRow(cursor.row);
2214 while (!cursor.par->Next()->table && cursor.par->Next()->Last()
2215 && cursor.par->Next()->IsNewline(0))
2216 cursor.par->Next()->Erase(0);
2218 InsertParagraph(cursor.par->Next(), cursor.row);
2220 UpdateCounters(cursor.row->previous);
2222 /* This check is necessary. Otherwise the new empty paragraph will
2223 * be deleted automatically. And it is more friendly for the user! */
2225 SetCursor(cursor.par->Next(), 0);
2227 SetCursor(cursor.par, 0);
2229 if (cursor.row->next)
2230 BreakAgain(cursor.row->next);
2236 void LyXText::OpenFootnote()
2238 LyXParagraph * endpar,* tmppar;
2241 LyXParagraph * par = cursor.par->ParFromPos(cursor.pos);
2243 /* if there is no footnote in this paragraph, just return. */
2245 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
2248 /* ok, move the cursor right before the footnote */
2250 /* just a little faster than using CursorRight() */
2251 for (cursor.pos = 0;
2252 cursor.par->ParFromPos(cursor.pos) != par; cursor.pos++);
2253 /* now the cursor is at the beginning of the physical par */
2254 SetCursor(cursor.par,
2255 cursor.pos + cursor.par->ParFromPos(cursor.pos)->text.size());
2257 /* the cursor must be exactly before the footnote */
2258 par = cursor.par->ParFromPos(cursor.pos);
2260 status = LyXText::NEED_MORE_REFRESH;
2261 refresh_row = cursor.row;
2262 refresh_y = cursor.y - cursor.row->baseline;
2264 tmppar = cursor.par;
2265 endpar = cursor.par->Next();
2268 tmppar->OpenFootnote(cursor.pos);
2269 RemoveParagraph(row);
2270 /* set the dimensions of the cursor row */
2271 row->fill = Fill(row, paperwidth);
2272 SetHeightOfRow(row);
2273 tmppar = tmppar->Next();
2275 while (tmppar != endpar) {
2277 InsertParagraph(tmppar, row);
2278 while (row->next && row->next->par == tmppar)
2280 tmppar = tmppar->Next();
2283 SetCursor(par->next, 0);
2284 sel_cursor = cursor;
2288 /* table stuff -- begin*/
2290 void LyXText::TableFeatures(int feature, string const & val) const
2292 if (!cursor.par->table)
2293 return; /* this should never happen */
2295 int actCell = NumberOfCell(cursor.par, cursor.pos);
2296 SetUndo(Undo::FINISH,
2297 cursor.par->ParFromPos(cursor.pos)->previous,
2298 cursor.par->ParFromPos(cursor.pos)->next);
2301 case LyXTable::SET_PWIDTH:
2302 cursor.par->table->SetPWidth(actCell, val);
2304 case LyXTable::SET_SPECIAL_COLUMN:
2305 case LyXTable::SET_SPECIAL_MULTI:
2306 cursor.par->table->SetAlignSpecial(actCell, val, feature);
2315 void LyXText::TableFeatures(int feature) const
2318 int setAlign = LYX_ALIGN_LEFT;
2322 if (!cursor.par->table)
2323 return; /* this should never happen */
2325 int actCell = NumberOfCell(cursor.par, cursor.pos);
2326 SetUndo(Undo::FINISH,
2327 cursor.par->ParFromPos(cursor.pos)->previous,
2328 cursor.par->ParFromPos(cursor.pos)->next);
2331 case LyXTable::ALIGN_LEFT:
2332 setAlign= LYX_ALIGN_LEFT;
2334 case LyXTable::ALIGN_RIGHT:
2335 setAlign= LYX_ALIGN_RIGHT;
2337 case LyXTable::ALIGN_CENTER:
2338 setAlign= LYX_ALIGN_CENTER;
2344 case LyXTable::APPEND_ROW: {
2345 LyXParagraph::size_type pos = cursor.pos;
2347 /* move to the next row */
2348 int cell_org = actCell;
2349 int cell = cell_org;
2351 // if there is a ContRow following this row I have to add
2352 // the row after the ContRow's
2353 if ((pos < cursor.par->Last()) &&
2354 cursor.par->table->RowHasContRow(cell_org)) {
2355 while((pos < cursor.par->Last()) &&
2356 !cursor.par->table->IsContRow(cell)) {
2357 while (pos < cursor.par->Last() &&
2358 !cursor.par->IsNewline(pos))
2360 if (pos < cursor.par->Last())
2364 while((pos < cursor.par->Last()) &&
2365 cursor.par->table->IsContRow(cell)) {
2366 while (pos < cursor.par->Last() &&
2367 !cursor.par->IsNewline(pos))
2369 if (pos < cursor.par->Last())
2374 if (pos < cursor.par->Last())
2377 while (pos < cursor.par->Last() &&
2378 (cell == cell_org || !cursor.par->table->IsFirstCell(cell))){
2379 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
2381 if (pos < cursor.par->Last())
2386 /* insert the new cells */
2387 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
2388 for (int i = 0; i < number; ++i)
2389 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
2391 /* append the row into the table */
2392 cursor.par->table->AppendRow(cell_org);
2396 case LyXTable::APPEND_CONT_ROW: {
2397 LyXParagraph::size_type pos = cursor.pos;
2398 /* move to the next row */
2399 int cell_org = actCell;
2400 int cell = cell_org;
2402 // if there is already a controw but not for this cell
2403 // the AppendContRow sets only the right values but does
2404 // not actually add a row
2405 if (cursor.par->table->RowHasContRow(cell_org) &&
2406 (cursor.par->table->CellHasContRow(cell_org)<0)) {
2407 cursor.par->table->AppendContRow(cell_org);
2411 while (pos < cursor.par->Last() &&
2413 || !cursor.par->table->IsFirstCell(cell))){
2414 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
2416 if (pos < cursor.par->Last())
2421 /* insert the new cells */
2422 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
2423 for (int i = 0; i < number; ++i)
2424 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
2426 /* append the row into the table */
2427 cursor.par->table->AppendContRow(cell_org);
2431 case LyXTable::APPEND_COLUMN: {
2432 LyXParagraph::size_type pos = 0;
2433 int cell_org = actCell;
2436 if (pos && (cursor.par->IsNewline(pos-1))){
2437 if (cursor.par->table->AppendCellAfterCell(cell_org, cell)){
2438 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
2439 if (pos <= cursor.pos)
2446 } while (pos <= cursor.par->Last());
2447 /* remember that the very last cell doesn't end with a newline.
2448 This saves one byte memory per table ;-) */
2449 if (cursor.par->table->AppendCellAfterCell(cell_org, cell))
2450 cursor.par->InsertChar(cursor.par->Last(), LyXParagraph::META_NEWLINE);
2452 /* append the column into the table */
2453 cursor.par->table->AppendColumn(cell_org);
2458 case LyXTable::DELETE_ROW:
2459 if (current_view->the_locking_inset)
2460 current_view->unlockInset(current_view->the_locking_inset);
2461 RemoveTableRow(&cursor);
2465 case LyXTable::DELETE_COLUMN: {
2466 LyXParagraph::size_type pos = 0;
2467 int cell_org = actCell;
2469 if (current_view->the_locking_inset)
2470 current_view->unlockInset(current_view->the_locking_inset);
2472 if (!pos || (cursor.par->IsNewline(pos-1))){
2473 if (cursor.par->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
2475 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
2476 cursor.par->Erase(pos);
2477 if (pos < cursor.par->Last())
2478 cursor.par->Erase(pos);
2480 cursor.par->Erase(pos - 1); // the missing newline at the end of a table
2481 --pos; // because of pos++ below
2486 } while (pos <= cursor.par->Last());
2488 /* delete the column from the table */
2489 cursor.par->table->DeleteColumn(cell_org);
2491 /* set the cursor to the beginning of the table, where else? */
2496 case LyXTable::TOGGLE_LINE_TOP:
2497 lineSet = !cursor.par->table->TopLine(actCell);
2499 cursor.par->table->SetTopLine(actCell, lineSet);
2501 LyXParagraph::size_type i;
2503 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
2504 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2505 cursor.par->table->SetTopLine(n, lineSet);
2513 case LyXTable::TOGGLE_LINE_BOTTOM:
2514 lineSet = !cursor.par->table->BottomLine(actCell);
2516 cursor.par->table->SetBottomLine(actCell, lineSet);
2518 LyXParagraph::size_type i;
2520 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2521 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2522 cursor.par->table->SetBottomLine(n, lineSet);
2530 case LyXTable::TOGGLE_LINE_LEFT:
2531 lineSet = !cursor.par->table->LeftLine(actCell);
2533 cursor.par->table->SetLeftLine(actCell, lineSet);
2535 LyXParagraph::size_type i;
2537 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
2538 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2539 cursor.par->table->SetLeftLine(n, lineSet);
2547 case LyXTable::TOGGLE_LINE_RIGHT:
2548 lineSet = !cursor.par->table->RightLine(actCell);
2550 cursor.par->table->SetRightLine(actCell, lineSet);
2553 LyXParagraph::size_type i = sel_start_cursor.pos;
2554 for (; i <= sel_end_cursor.pos; ++i) {
2555 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2556 cursor.par->table->SetRightLine(n, lineSet);
2564 case LyXTable::ALIGN_LEFT:
2565 case LyXTable::ALIGN_RIGHT:
2566 case LyXTable::ALIGN_CENTER:
2568 cursor.par->table->SetAlignment(actCell, setAlign);
2571 LyXParagraph::size_type i = sel_start_cursor.pos;
2572 for (; i <= sel_end_cursor.pos; ++i) {
2573 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2574 cursor.par->table->SetAlignment(n, setAlign);
2582 case LyXTable::DELETE_TABLE:
2583 SetCursorIntern(cursor.par, 0);
2584 delete cursor.par->table;
2585 cursor.par->table = 0;
2586 // temporary: Should put table in simple_cut_buffer (with before and after
2587 // dummy-paragraph !!
2588 // not necessar anymore with UNDO :)
2589 for (LyXParagraph::size_type i =
2590 cursor.par->text.size() - 1; i >= 0; --i)
2591 cursor.par->Erase(i);
2595 case LyXTable::MULTICOLUMN: {
2597 // check wether we are completly in a multicol
2598 int multicol = cursor.par->table->IsMultiColumn(actCell);
2599 if (multicol && selection && sel_start_cursor.row == sel_end_cursor.row){
2600 multicol = NumberOfCell(sel_start_cursor.par, sel_start_cursor.pos)
2601 == NumberOfCell(sel_end_cursor.par, sel_end_cursor.pos);
2605 int newlines = cursor.par->table->UnsetMultiColumn(actCell);
2606 LyXParagraph::size_type pos = cursor.pos;
2607 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
2609 for (; newlines; --newlines)
2610 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
2615 // selection must be in one row (or no selection)
2617 cursor.par->table->SetMultiColumn(NumberOfCell(cursor.par,
2624 if (sel_start_cursor.row == sel_end_cursor.row){
2625 LyXParagraph::size_type i;
2627 for (i = sel_start_cursor.pos;
2628 i < sel_end_cursor.pos; ++i){
2629 if (sel_start_cursor.par->IsNewline(i)){
2630 sel_start_cursor.par->Erase(i);
2631 // check for double-blanks
2632 if ((i && !sel_start_cursor.par->IsLineSeparator(i-1))
2634 (i < sel_start_cursor.par->Last()
2635 && !sel_start_cursor.par->IsLineSeparator(i)))
2636 sel_start_cursor.par->InsertChar(i, ' ');
2638 sel_end_cursor.pos--;
2645 SetMultiColumn(NumberOfCell(sel_start_cursor.par,
2646 sel_start_cursor.pos),
2648 cursor.pos = sel_start_cursor.pos;
2653 WriteAlert(_("Impossible Operation!"),
2654 _("Multicolumns can only be horizontally."),
2661 case LyXTable::SET_ALL_LINES:
2663 case LyXTable::UNSET_ALL_LINES:
2665 cursor.par->table->SetAllLines(NumberOfCell(cursor.par,
2669 LyXParagraph::size_type i;
2671 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2672 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2673 cursor.par->table->SetAllLines(n, setLines);
2680 case LyXTable::SET_LONGTABLE:
2681 cursor.par->table->SetLongTable(true);
2683 case LyXTable::UNSET_LONGTABLE:
2684 cursor.par->table->SetLongTable(false);
2686 case LyXTable::SET_ROTATE_TABLE:
2687 cursor.par->table->SetRotateTable(true);
2689 case LyXTable::UNSET_ROTATE_TABLE:
2690 cursor.par->table->SetRotateTable(false);
2692 case LyXTable::SET_ROTATE_CELL:
2694 cursor.par->table->SetRotateCell(actCell, true);
2696 LyXParagraph::size_type i;
2698 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
2699 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2700 cursor.par->table->SetRotateCell(n, true);
2706 case LyXTable::UNSET_ROTATE_CELL:
2708 cursor.par->table->SetRotateCell(actCell, false);
2711 LyXParagraph::size_type i = sel_start_cursor.pos;
2712 for (; i <= sel_end_cursor.pos; ++i) {
2713 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2714 cursor.par->table->SetRotateCell(n, false);
2720 case LyXTable::SET_LINEBREAKS:
2721 what = !cursor.par->table->Linebreaks(cursor.par->table->FirstVirtualCell(actCell));
2723 cursor.par->table->SetLinebreaks(actCell, what);
2725 LyXParagraph::size_type i;
2727 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2728 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2729 cursor.par->table->SetLinebreaks(n, what);
2735 case LyXTable::SET_LTFIRSTHEAD:
2736 cursor.par->table->SetLTHead(actCell, true);
2738 case LyXTable::SET_LTHEAD:
2739 cursor.par->table->SetLTHead(actCell, false);
2741 case LyXTable::SET_LTFOOT:
2742 cursor.par->table->SetLTFoot(actCell, false);
2744 case LyXTable::SET_LTLASTFOOT:
2745 cursor.par->table->SetLTFoot(actCell, true);
2747 case LyXTable::SET_LTNEWPAGE:
2748 what = !cursor.par->table->LTNewPage(actCell);
2749 cursor.par->table->SetLTNewPage(actCell, what);
2755 void LyXText::InsertCharInTable(char c)
2760 bool jumped_over_space;
2762 /* first check, if there will be two blanks together or a blank at
2763 * the beginning of a paragraph.
2764 * I decided to handle blanks like normal characters, the main
2765 * difference are the special checks when calculating the row.fill
2766 * (blank does not count at the end of a row) and the check here */
2768 LyXFont realtmpfont = real_current_font;
2769 LyXFont rawtmpfont = current_font; /* store the current font.
2770 * This is because of the use
2771 * of cursor movements. The moving
2772 * cursor would refresh the
2775 // Get the font that is used to calculate the baselineskip
2776 LyXParagraph::size_type const lastpos =
2778 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2780 jumped_over_space = false;
2781 if (IsLineSeparatorChar(c)) {
2783 /* avoid double blanks but insert the new blank because
2784 * of a possible font change */
2785 if (cursor.pos < lastpos &&
2786 cursor.par->IsLineSeparator(cursor.pos))
2788 cursor.par->Erase(cursor.pos);
2789 jumped_over_space = true;
2791 else if ((cursor.pos > 0 &&
2792 cursor.par->IsLineSeparator(cursor.pos - 1))
2793 || (cursor.pos > 0 && cursor.par->IsNewline(cursor.pos - 1))
2794 || (cursor.pos == 0 &&
2795 !(cursor.par->Previous()
2796 && cursor.par->Previous()->footnoteflag
2797 == LyXParagraph::OPEN_FOOTNOTE)))
2800 else if (IsNewlineChar(c)) {
2801 if (!IsEmptyTableCell()) {
2802 TableFeatures(LyXTable::APPEND_CONT_ROW);
2809 y = cursor.y - row->baseline;
2810 if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset
2811 * already inserted the character */
2812 cursor.par->InsertChar(cursor.pos, c);
2813 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2815 if (!jumped_over_space) {
2816 /* refresh the positions */
2818 while (tmprow->next && tmprow->next->par == row->par) {
2819 tmprow = tmprow->next;
2826 CheckParagraphInTable(cursor.par, cursor.pos);
2828 current_font = rawtmpfont;
2829 real_current_font = realtmpfont;
2831 /* check, whether the last character's font has changed. */
2832 if (cursor.pos && cursor.pos == cursor.par->Last()
2833 && rawparfont != rawtmpfont)
2834 RedoHeightOfParagraph(cursor);
2838 void LyXText::CheckParagraphInTable(LyXParagraph * par,
2839 LyXParagraph::size_type pos)
2842 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
2843 par->GetInset(pos) && par->GetInset(pos)->display()){
2844 par->GetInset(pos)->display(false);
2848 Row * row = GetRow(par, pos, y);
2850 int tmpheight = row->height;
2851 SetHeightOfRow(row);
2853 LyXParagraph::size_type tmp_pos = pos;
2854 /* update the table information */
2855 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2857 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2858 WidthOfCell(par, tmp_pos))) {
2859 LyXCursor tmpcursor = cursor;
2860 SetCursorIntern(par, pos);
2861 /* make a complete redraw */
2862 RedoDrawingOfParagraph(cursor);
2866 /* redraw only the row */
2867 LyXCursor tmpcursor = cursor;
2868 SetCursorIntern(par, pos);
2870 refresh_x = cursor.x;
2872 refresh_pos = cursor.pos;
2875 if (tmpheight == row->height)
2876 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2878 status = LyXText::NEED_MORE_REFRESH;
2880 SetCursorIntern(cursor.par, cursor.pos);
2884 void LyXText::BackspaceInTable()
2886 Row * tmprow, * row;
2889 LyXFont rawtmpfont = current_font;
2890 LyXFont realtmpfont = real_current_font;
2892 // Get the font that is used to calculate the baselineskip
2893 int const lastpos = cursor.par->Last();
2894 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2896 if (cursor.pos == 0) {
2897 /* no pasting of table paragraphs */
2902 /* this is the code for a normal backspace, not pasting
2904 SetUndo(Undo::DELETE,
2905 cursor.par->ParFromPos(cursor.pos)->previous,
2906 cursor.par->ParFromPos(cursor.pos)->next);
2910 /* some insets are undeletable here */
2911 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
2912 if (!cursor.par->GetInset(cursor.pos)->Deletable())
2917 y = cursor.y - row->baseline;
2919 /* some special code when deleting a newline. */
2920 if (cursor.par->IsNewline(cursor.pos)) {
2925 cursor.par->Erase(cursor.pos);
2927 /* refresh the positions */
2929 while (tmprow->next && tmprow->next->par == row->par) {
2930 tmprow = tmprow->next;
2934 /* delete superfluous blanks */
2935 if (cursor.pos < cursor.par->Last() - 1 &&
2936 (cursor.par->IsLineSeparator(cursor.pos))) {
2938 if (cursor.pos == BeginningOfMainBody(cursor.par)
2940 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
2941 cursor.par->Erase(cursor.pos);
2942 /* refresh the positions */
2944 while (tmprow->next &&
2945 tmprow->next->par == row->par) {
2946 tmprow = tmprow->next;
2949 if (cursor.pos) /* move one character left */
2955 CheckParagraphInTable(cursor.par, cursor.pos);
2957 /* check, wether the last characters font has changed. */
2958 if (cursor.pos && cursor.pos == cursor.par->Last()
2959 && rawparfont != rawtmpfont)
2960 RedoHeightOfParagraph(cursor);
2962 /* restore the current font
2963 * That is what a user expects! */
2964 current_font = rawtmpfont;
2965 real_current_font = realtmpfont;
2967 SetCursorIntern(cursor.par, cursor.pos);
2970 /* table stuff -- end*/
2973 /* just a macro to make some thing easier. */
2974 void LyXText::RedoParagraph() const
2977 // I suspect this version will work
2980 RedoParagraphs(cursor, cursor.par->Next());
2981 SetCursorIntern(cursor.par, cursor.pos);
2983 LyXCursor tmpcursor = cursor;
2985 RedoParagraphs(cursor, cursor.par->Next());
2986 SetCursorIntern(tmpcursor.par, tmpcursor.pos);
2991 /* insert a character, moves all the following breaks in the
2992 * same Paragraph one to the right and make a rebreak */
2993 void LyXText::InsertChar(char c)
2995 SetUndo(Undo::INSERT,
2996 cursor.par->ParFromPos(cursor.pos)->previous,
2997 cursor.par->ParFromPos(cursor.pos)->next);
2999 /* When the free-spacing option is set for the current layout,
3000 * all spaces are converted to protected spaces. */
3001 bool freeSpacingBo =
3002 textclasslist.Style(parameters->textclass,
3003 cursor.row->par->GetLayout()).free_spacing;
3005 if (freeSpacingBo && IsLineSeparatorChar(c)
3006 && (!cursor.pos || cursor.par->IsLineSeparator(cursor.pos - 1)))
3007 c = LyXParagraph::META_PROTECTED_SEPARATOR;
3009 /* table stuff -- begin*/
3010 if (cursor.par->table) {
3011 InsertCharInTable(c);
3015 /* table stuff -- end*/
3017 /* First check, if there will be two blanks together or a blank at
3018 the beginning of a paragraph.
3019 I decided to handle blanks like normal characters, the main
3020 difference are the special checks when calculating the row.fill
3021 (blank does not count at the end of a row) and the check here */
3023 // The bug is triggered when we type in a description environment:
3024 // The current_font is not changed when we go from label to main text
3025 // and it should (along with realtmpfont) when we type the space.
3026 #ifdef WITH_WARNINGS
3027 #warning There is a bug here! (Asger)
3030 LyXFont realtmpfont = real_current_font;
3031 LyXFont rawtmpfont = current_font; /* store the current font.
3032 * This is because of the use
3033 * of cursor movements. The moving
3034 * cursor would refresh the
3037 // Get the font that is used to calculate the baselineskip
3038 LyXParagraph::size_type lastpos = cursor.par->Last();
3039 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
3041 bool jumped_over_space = false;
3043 if (IsLineSeparatorChar(c)) {
3044 #ifndef FIX_DOUBLE_SPACE
3045 if (cursor.pos < lastpos
3046 && cursor.par->IsLineSeparator(cursor.pos)) {
3047 /* the user inserted a space before a space. So we
3048 * will just make a CursorRight. BUT: The font of this
3049 * space should be set to current font. That is why
3050 * we need to rebreak perhaps. If there is a protected
3051 * blank at the end of a row we have to force
3054 current_view->owner()->getMiniBuffer()
3055 ->Set(_("You cannot type two spaces this way. "
3056 " Please read the Tutorial."));
3058 // How can this ever happen?
3059 if (cursor.pos == RowLast(cursor.row)
3060 && !IsLineSeparatorChar(c))
3061 cursor.row->fill = -1; // force rebreak
3062 cursor.par->Erase(cursor.pos);
3063 jumped_over_space = true;
3065 // Seems to me that this works just as well.
3073 && cursor.par->IsLineSeparator(cursor.pos - 1))
3075 && cursor.par->IsNewline(cursor.pos - 1))
3077 && !(cursor.par->Previous()
3078 && cursor.par->Previous()->footnoteflag
3079 == LyXParagraph::OPEN_FOOTNOTE))) {
3080 if (cursor.pos == 0 )
3081 current_view->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
3083 current_view->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
3087 } else if (IsNewlineChar(c)) {
3088 if (cursor.par->FirstPhysicalPar() == cursor.par
3089 && cursor.pos <= BeginningOfMainBody(cursor.par)) {
3093 /* No newline at first position
3094 * of a paragraph or behind labels.
3095 * TeX does not allow that. */
3097 if (cursor.pos < cursor.par->Last() &&
3098 cursor.par->IsLineSeparator(cursor.pos))
3099 CursorRightIntern(); // newline always after a blank!
3100 cursor.row->fill = -1; // to force a new break
3103 // the display inset stuff
3104 if (cursor.row->par->GetChar(cursor.row->pos) == LyXParagraph::META_INSET
3105 && cursor.row->par->GetInset(cursor.row->pos)
3106 && cursor.row->par->GetInset(cursor.row->pos)->display())
3107 cursor.row->fill = -1; // to force a new break
3109 // get the cursor row fist
3110 Row * row = cursor.row;
3111 long y = cursor.y - row->baseline;
3112 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
3113 * already insertet the character */
3114 cursor.par->InsertChar(cursor.pos, c);
3115 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
3117 if (!jumped_over_space) {
3118 // refresh the positions
3120 while (tmprow->next && tmprow->next->par == row->par) {
3121 tmprow = tmprow->next;
3126 // Is there a break one row above
3127 if ((cursor.par->IsLineSeparator(cursor.pos)
3128 || cursor.par->IsNewline(cursor.pos)
3129 || cursor.row->fill == -1)
3130 && row->previous && row->previous->par == row->par) {
3131 LyXParagraph::size_type z = NextBreakPoint(row->previous,
3133 if ( z >= row->pos) {
3136 // set the dimensions of the row above
3137 row->previous->fill = Fill(row->previous, paperwidth);
3139 SetHeightOfRow(row->previous);
3141 y -= row->previous->height;
3143 refresh_row = row->previous;
3144 status = LyXText::NEED_MORE_REFRESH;
3146 BreakAgainOneRow(row);
3148 current_font = rawtmpfont;
3149 real_current_font = realtmpfont;
3150 SetCursor(cursor.par, cursor.pos + 1, false);
3151 /* cursor MUST be in row now */
3153 if (row->next && row->next->par == row->par)
3154 need_break_row = row->next;
3158 // check, wether the last characters font has changed.
3159 if (cursor.pos && cursor.pos == cursor.par->Last()
3160 && rawparfont != rawtmpfont)
3161 RedoHeightOfParagraph(cursor);
3168 /* recalculate the fill of the row */
3169 if (row->fill >= 0) /* needed because a newline
3170 * will set fill to -1. Otherwise
3171 * we would not get a rebreak! */
3172 row->fill = Fill(row, paperwidth);
3173 if (row->fill < 0 ) {
3176 refresh_x = cursor.x;
3177 refresh_pos = cursor.pos;
3178 status = LyXText::NEED_MORE_REFRESH;
3179 BreakAgainOneRow(row);
3180 /* will the cursor be in another row now? */
3181 if (RowLast(row) <= cursor.pos + 1 && row->next) {
3182 if (row->next && row->next->par == row->par)
3186 BreakAgainOneRow(row);
3188 current_font = rawtmpfont;
3189 real_current_font = realtmpfont;
3190 SetCursor(cursor.par, cursor.pos + 1, false);
3191 if (row->next && row->next->par == row->par)
3192 need_break_row = row->next;
3197 refresh_x = cursor.x;
3199 refresh_pos = cursor.pos;
3201 int tmpheight = row->height;
3202 SetHeightOfRow(row);
3203 if (tmpheight == row->height)
3204 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3206 status = LyXText::NEED_MORE_REFRESH;
3208 current_font = rawtmpfont;
3209 real_current_font = realtmpfont;
3210 SetCursor(cursor.par, cursor.pos + 1, false);
3213 /* check, wether the last characters font has changed. */
3214 if (cursor.pos && cursor.pos == cursor.par->Last()
3215 && rawparfont != rawtmpfont) {
3216 RedoHeightOfParagraph(cursor);
3218 /* now the special right address boxes */
3219 if (textclasslist.Style(parameters->textclass,
3220 cursor.par->GetLayout()).margintype
3221 == MARGIN_RIGHT_ADDRESS_BOX) {
3222 RedoDrawingOfParagraph(cursor);
3230 void LyXText::charInserted()
3232 // Here we could call FinishUndo for every 20 characters inserted.
3233 // This is from my experience how emacs does it.
3234 static unsigned int counter = 0;
3243 void LyXText::PrepareToPrint(Row * row, float & x,
3244 float & fill_separator,
3246 float & fill_label_hfill,
3251 float w = row->fill;
3253 fill_label_hfill = 0;
3255 fill_label_hfill = 0;
3257 LyXDirection direction = row->par->getParDirection();
3259 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
3260 x = RightMargin(row);
3261 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3262 LyXFont font(LyXFont::ALL_SANE);
3263 font.setSize(LyXFont::SIZE_SMALL);
3264 x += font.textWidth("Mwide-figM", 10);
3268 x = LeftMargin(row);
3270 /* is there a manual margin with a manual label */
3271 if (textclasslist.Style(parameters->textclass,
3272 row->par->GetLayout()).margintype == MARGIN_MANUAL
3273 && textclasslist.Style(parameters->textclass,
3274 row->par->GetLayout()).labeltype == LABEL_MANUAL) {
3276 nlh = NumberOfLabelHfills(row) + 1; /* one more since labels
3277 * are left aligned*/
3278 if (nlh && !row->par->GetLabelWidthString().empty()) {
3279 fill_label_hfill = LabelFill(row) / nlh;
3283 /* are there any hfills in the row? */
3284 nh = NumberOfHfills(row);
3286 /* table stuff -- begin*/
3287 if (row->par->table) {
3288 w = paperwidth - row->par->table->WidthOfTable()
3289 - x - RightMargin(row);
3290 nh = 0; /* ignore hfills in tables */
3292 /* table stuff -- end*/
3297 /* is it block, flushleft or flushright?
3298 * set x how you need it */
3300 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
3301 align = textclasslist.Style(parameters->textclass, row->par->GetLayout()).align;
3303 align = row->par->FirstPhysicalPar()->align;
3305 /* center displayed insets */
3306 if (row->par->GetChar(row->pos) == LyXParagraph::META_INSET
3307 && row->par->GetInset(row->pos)
3308 && row->par->GetInset(row->pos)->display())
3309 align = LYX_ALIGN_CENTER;
3312 case LYX_ALIGN_BLOCK:
3313 ns = NumberOfSeparators(row);
3314 if (ns && row->next && row->next->par == row->par &&
3315 !(row->next->par->IsNewline(row->next->pos-1))
3316 && !(row->next->par->GetChar(row->next->pos) == LyXParagraph::META_INSET
3317 && row->next->par->GetInset(row->next->pos)
3318 && row->next->par->GetInset(row->next->pos)->display())
3320 fill_separator = w / ns;
3321 else if (direction == LYX_DIR_RIGHT_TO_LEFT)
3324 case LYX_ALIGN_RIGHT:
3327 case LYX_ALIGN_CENTER:
3335 ComputeBidiTables(row);
3336 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
3337 LyXParagraph::size_type main_body =
3338 BeginningOfMainBody(row->par);
3339 LyXParagraph::size_type last = RowLast(row);
3341 if (row->pos <= last
3343 && last != vis2log(last)
3344 && row->par->IsLineSeparator(last)) {
3345 if (!(main_body > 0 && main_body-1 == last))
3346 x -= fill_separator+SingleWidth(row->par,last);
3347 } else if (main_body > 0 &&
3348 (main_body-1 > last ||
3349 !row->par->IsLineSeparator(main_body-1))) {
3350 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
3351 row->par->GetLayout());
3352 x += GetFont(row->par, -2).stringWidth(layout.labelsep);
3353 if (main_body-1 <= last)
3354 x += fill_label_hfill;
3359 /* important for the screen */
3362 /* the cursor set functions have a special mechanism. When they
3363 * realize, that you left an empty paragraph, they will delete it.
3364 * They also delete the corresponding row */
3366 void LyXText::CursorRightOneWord() const
3368 // treat floats, HFills and Insets as words
3369 LyXCursor tmpcursor = cursor;
3371 if (tmpcursor.pos == tmpcursor.par->Last()
3372 && tmpcursor.par->Next())
3374 tmpcursor.par = tmpcursor.par->Next();
3379 // Skip through initial nonword stuff.
3380 while ( tmpcursor.pos < tmpcursor.par->Last() &&
3381 ! tmpcursor.par->IsWord( tmpcursor.pos ) )
3383 // printf("Current pos1 %d", tmpcursor.pos) ;
3387 // Advance through word.
3388 while ( tmpcursor.pos < tmpcursor.par->Last() &&
3389 tmpcursor.par->IsWord( tmpcursor.pos ) )
3391 // printf("Current pos2 %d", tmpcursor.pos) ;
3396 SetCursor(tmpcursor.par, tmpcursor.pos);
3400 void LyXText::CursorTab() const
3402 if (cursor.par->table) {
3403 int cell = NumberOfCell(cursor.par, cursor.pos);
3404 while(cursor.par->table->IsContRow(cell)) {
3406 cell = NumberOfCell(cursor.par, cursor.pos);
3408 if (cursor.par->table->ShouldBeVeryLastCell(cell))
3409 TableFeatures(LyXTable::APPEND_ROW);
3411 LyXCursor tmpcursor = cursor;
3412 while (tmpcursor.pos < tmpcursor.par->Last()
3413 && !tmpcursor.par->IsNewline(tmpcursor.pos))
3416 if (tmpcursor.pos == tmpcursor.par->Last()){
3417 if (tmpcursor.par->Next()) {
3418 tmpcursor.par = tmpcursor.par->Next();
3424 SetCursor(tmpcursor.par, tmpcursor.pos);
3425 if (cursor.par->table) {
3426 int cell = NumberOfCell(cursor.par, cursor.pos);
3427 while (cursor.par->table->IsContRow(cell) &&
3428 !cursor.par->table->ShouldBeVeryLastCell(cell)) {
3430 while (tmpcursor.pos < tmpcursor.par->Last()
3431 && !tmpcursor.par->IsNewline(tmpcursor.pos))
3434 if (tmpcursor.pos == tmpcursor.par->Last()){
3435 if (tmpcursor.par->Next()) {
3436 tmpcursor.par = tmpcursor.par->Next();
3442 SetCursor(tmpcursor.par, tmpcursor.pos);
3443 cell = NumberOfCell(cursor.par, cursor.pos);
3449 /* -------> Skip initial whitespace at end of word and move cursor to *start*
3450 of prior word, not to end of next prior word. */
3452 void LyXText::CursorLeftOneWord() const
3454 // treat HFills, floats and Insets as words
3455 LyXCursor tmpcursor = cursor;
3456 while (tmpcursor.pos
3457 && (tmpcursor.par->IsSeparator(tmpcursor.pos - 1)
3458 || tmpcursor.par->IsKomma(tmpcursor.pos - 1))
3459 && !(tmpcursor.par->IsHfill(tmpcursor.pos - 1)
3460 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
3461 || tmpcursor.par->IsInset(tmpcursor.pos - 1)))
3465 && (tmpcursor.par->IsInset(tmpcursor.pos - 1)
3466 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
3467 || tmpcursor.par->IsHfill(tmpcursor.pos - 1))) {
3469 } else if (!tmpcursor.pos) {
3470 if (tmpcursor.par->Previous()){
3471 tmpcursor.par = tmpcursor.par->Previous();
3472 tmpcursor.pos = tmpcursor.par->Last();
3474 } else { // Here, tmpcursor != 0
3475 while (tmpcursor.pos > 0 &&
3476 tmpcursor.par->IsWord(tmpcursor.pos-1) )
3479 SetCursor(tmpcursor.par, tmpcursor.pos);
3482 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
3485 void LyXText::SelectWord()
3487 /* Move cursor to the beginning, when not already there. */
3489 && !cursor.par->IsSeparator(cursor.pos-1)
3490 && !cursor.par->IsKomma(cursor.pos-1) )
3491 CursorLeftOneWord();
3493 /* set the sel cursor */
3494 sel_cursor = cursor;
3496 while ( cursor.pos < cursor.par->Last()
3497 && !cursor.par->IsSeparator(cursor.pos)
3498 && !cursor.par->IsKomma(cursor.pos) )
3500 SetCursor( cursor.par, cursor.pos );
3502 /* finally set the selection */
3507 /* -------> Select the word currently under the cursor when:
3508 1: no selection is currently set,
3509 2: the cursor is not at the borders of the word. */
3511 int LyXText::SelectWordWhenUnderCursor()
3513 if ( selection ) return 0;
3514 if ( cursor.pos < cursor.par->Last()
3515 && !cursor.par->IsSeparator(cursor.pos)
3516 && !cursor.par->IsKomma(cursor.pos)
3518 && !cursor.par->IsSeparator(cursor.pos -1)
3519 && !cursor.par->IsKomma(cursor.pos -1) ) {
3527 // This function is only used by the spellchecker for NextWord().
3528 // It doesn't handle LYX_ACCENTs and probably never will.
3529 char * LyXText::SelectNextWord(float & value)
3531 LyXParagraph * tmppar = cursor.par;
3533 // If this is not the very first word, skip rest of
3534 // current word because we are probably in the middle
3535 // of a word if there is text here.
3536 if (cursor.pos || cursor.par->previous) {
3537 while (cursor.pos < cursor.par->Last()
3538 && cursor.par->IsLetter(cursor.pos))
3541 // Now, skip until we have real text (will jump paragraphs)
3542 while ((cursor.par->Last() > cursor.pos
3543 && (!cursor.par->IsLetter(cursor.pos)
3544 || cursor.par->getFont(cursor.pos).latex() == LyXFont::ON))
3545 || (cursor.par->Last() == cursor.pos
3546 && cursor.par->Next())){
3547 if (cursor.pos == cursor.par->Last()) {
3548 cursor.par = cursor.par->Next();
3555 // Update the value if we changed paragraphs
3556 if (cursor.par != tmppar){
3557 SetCursor(cursor.par, cursor.pos);
3558 value = float(cursor.y)/float(height);
3561 /* Start the selection from here */
3562 sel_cursor = cursor;
3566 /* and find the end of the word
3567 (optional hyphens are part of a word) */
3568 while (cursor.pos < cursor.par->Last()
3569 && (cursor.par->IsLetter(cursor.pos))
3570 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET &&
3571 cursor.par->GetInset(cursor.pos) != 0 &&
3572 cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 &&
3576 // Finally, we copy the word to a string and return it
3579 if (sel_cursor.pos < cursor.pos) {
3580 str = new char [cursor.pos - sel_cursor.pos + 2];
3581 LyXParagraph::size_type i, j;
3582 for (i = sel_cursor.pos, j = 0; i < cursor.pos; ++i) {
3583 if (cursor.par->GetChar(i) != LyXParagraph::META_INSET)
3584 str[j++] = cursor.par->GetChar(i);
3592 // This one is also only for the spellchecker
3593 void LyXText::SelectSelectedWord()
3595 /* move cursor to the beginning */
3596 SetCursor(sel_cursor.par, sel_cursor.pos);
3598 /* set the sel cursor */
3599 sel_cursor = cursor;
3603 /* now find the end of the word */
3604 while (cursor.pos < cursor.par->Last()
3605 && (cursor.par->IsLetter(cursor.pos)
3606 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET &&
3607 cursor.par->GetInset(cursor.pos) != 0 &&
3608 cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 &&
3612 SetCursor(cursor.par, cursor.pos);
3614 /* finally set the selection */
3619 /* -------> Delete from cursor up to the end of the current or next word. */
3620 void LyXText::DeleteWordForward()
3622 LyXCursor tmpcursor = cursor;
3624 if (!cursor.par->Last())
3627 /* -------> Skip initial non-word stuff. */
3628 while ( cursor.pos < cursor.par->Last()
3629 && (cursor.par->IsSeparator(cursor.pos)
3630 || cursor.par->IsKomma(cursor.pos)) )
3633 SetCursorIntern(cursor.par, cursor.pos);
3634 selection = True; // to avoid deletion
3635 CursorRightOneWord();
3636 sel_cursor = cursor;
3640 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3646 /* -------> Delete from cursor to start of current or prior word. */
3647 void LyXText::DeleteWordBackward()
3649 LyXCursor tmpcursor = cursor;
3650 if (!cursor.par->Last())
3653 selection = true; // to avoid deletion
3654 CursorLeftOneWord();
3655 sel_cursor = cursor;
3663 /* -------> Kill to end of line. */
3664 void LyXText::DeleteLineForward()
3666 LyXCursor tmpcursor = cursor;
3667 if (!cursor.par->Last())
3671 sel_cursor = cursor;
3674 if (selection == false) {
3675 DeleteWordForward();
3683 // Change the case of a word at cursor position. The meaning of action
3685 // 0 change to lowercase
3686 // 1 capitalize word
3687 // 2 change to uppercase
3688 // This function directly manipulates LyXParagraph::text because there
3689 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3690 // that it is correct. I guess part of it should be moved to
3691 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3692 // it does not access outside of the allocated array as the older
3693 // version did. (JMarc)
3694 void LyXText::ChangeWordCase(LyXText::TextCase action)
3696 LyXParagraph * tmppar = cursor.par->ParFromPos(cursor.pos);
3698 SetUndo(Undo::FINISH, tmppar->previous, tmppar->next);
3700 LyXParagraph::size_type tmppos =
3701 cursor.par->PositionInParFromPos(cursor.pos);
3702 while (tmppos < tmppar->size()) {
3703 unsigned char c = tmppar->text[tmppos];
3704 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3706 if (c != LyXParagraph::META_INSET) {
3708 case text_lowercase:
3711 case text_capitalization:
3713 action = text_lowercase;
3715 case text_uppercase:
3721 tmppar->text[tmppos] = c;
3724 CheckParagraph(tmppar, tmppos);
3725 CursorRightOneWord();
3729 void LyXText::Delete()
3731 // this is a very easy implementation
3733 LyXCursor old_cursor = cursor;
3734 int old_cur_par_id = old_cursor.par->id();
3735 int old_cur_par_prev_id = old_cursor.par->previous ?
3736 old_cursor.par->previous->id() : 0;
3738 // just move to the right
3739 CursorRightIntern();
3741 // This check is not very good...
3742 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3743 // and that can very well delete the par or par->previous in
3744 // old_cursor. Will a solution where we compare paragraph id's
3747 if ((cursor.par->previous ? cursor.par->previous->id() : 0)
3748 == old_cur_par_prev_id
3749 && cursor.par->id() != old_cur_par_id)
3750 return; // delete-empty-paragraph-mechanism has done it
3752 if (cursor.par->previous == old_cursor.par->previous
3753 && cursor.par != old_cursor.par)
3754 return; // delete-empty-paragraph-mechanism has done it
3756 // if you had success make a backspace
3757 if (old_cursor.par != cursor.par || old_cursor.pos != cursor.pos) {
3758 LyXCursor tmpcursor = cursor;
3759 cursor = old_cursor; // to make sure undo gets the right cursor position
3760 SetUndo(Undo::DELETE,
3761 cursor.par->ParFromPos(cursor.pos)->previous,
3762 cursor.par->ParFromPos(cursor.pos)->next);
3769 void LyXText::Backspace()
3771 LyXParagraph * tmppar;
3772 Row * tmprow, * row;
3776 /* table stuff -- begin */
3777 if (cursor.par->table) {
3781 /* table stuff -- end */
3783 LyXFont rawtmpfont = current_font;
3784 LyXFont realtmpfont = real_current_font;
3786 // Get the font that is used to calculate the baselineskip
3787 int const lastpos = cursor.par->Last();
3788 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
3790 if (cursor.pos == 0) {
3791 // we may paste some paragraphs
3793 // is it an empty paragraph?
3796 || (lastpos == 1 && cursor.par->IsSeparator(0)))
3797 && !(cursor.par->Next()
3798 && cursor.par->footnoteflag ==
3799 LyXParagraph::NO_FOOTNOTE
3800 && cursor.par->Next()->footnoteflag ==
3801 LyXParagraph::OPEN_FOOTNOTE)) {
3803 if (cursor.par->previous) {
3804 tmppar = cursor.par->previous->FirstPhysicalPar();
3805 if (cursor.par->GetLayout() == tmppar->GetLayout()
3806 && cursor.par->footnoteflag == tmppar->footnoteflag
3807 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3809 tmppar->line_bottom = cursor.par->line_bottom;
3810 tmppar->added_space_bottom = cursor.par->added_space_bottom;
3811 tmppar->pagebreak_bottom = cursor.par->pagebreak_bottom;
3816 // the layout things can change the height of a row !
3817 tmpheight = cursor.row->height;
3818 SetHeightOfRow(cursor.row);
3819 if (cursor.row->height != tmpheight) {
3820 refresh_y = cursor.y - cursor.row->baseline;
3821 refresh_row = cursor.row;
3822 status = LyXText::NEED_MORE_REFRESH;
3827 if (cursor.par->ParFromPos(cursor.pos)->previous){
3828 SetUndo(Undo::DELETE,
3829 cursor.par->ParFromPos(cursor.pos)->previous->previous,
3830 cursor.par->ParFromPos(cursor.pos)->next);
3832 tmppar = cursor.par;
3833 tmprow = cursor.row;
3835 /* Pasting is not allowed, if the paragraphs have different
3836 layout. I think it is a real bug of all other
3837 word processors to allow it. It confuses the user.
3838 Even so with a footnote paragraph and a non-footnote
3839 paragraph. I will not allow pasting in this case,
3840 because the user would be confused if the footnote behaves
3841 different wether it is open or closed.
3843 Correction: Pasting is always allowed with standard-layout
3845 if (cursor.par != tmppar
3846 && (cursor.par->GetLayout() == tmppar->GetLayout()
3847 || !tmppar->GetLayout())
3848 && cursor.par->footnoteflag == tmppar->footnoteflag
3849 /* table stuff -- begin*/
3850 && !cursor.par->table /* no pasting of tables */
3851 /* table stuff -- end*/
3852 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3854 cursor.par->PasteParagraph();
3857 cursor.par->IsSeparator(cursor.pos - 1)))
3858 cursor.par->InsertChar(cursor.pos, ' ');
3863 status = LyXText::NEED_MORE_REFRESH;
3864 refresh_row = cursor.row;
3865 refresh_y = cursor.y - cursor.row->baseline;
3867 // remove the lost paragraph
3868 RemoveParagraph(tmprow);
3871 AppendParagraph(cursor.row);
3872 UpdateCounters(cursor.row);
3874 // the row may have changed, block, hfills etc.
3875 SetCursor(cursor.par, cursor.pos);
3878 /* this is the code for a normal backspace, not pasting
3880 SetUndo(Undo::DELETE,
3881 cursor.par->ParFromPos(cursor.pos)->previous,
3882 cursor.par->ParFromPos(cursor.pos)->next);
3885 // some insets are undeletable here
3886 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
3887 if (!cursor.par->GetInset(cursor.pos)->Deletable())
3889 // force complete redo when erasing display insets
3890 // this is a cruel mathod but save..... Matthias
3891 if (cursor.par->GetInset(cursor.pos)->display()){
3892 cursor.par->Erase(cursor.pos);
3899 y = cursor.y - row->baseline;
3900 LyXParagraph::size_type z;
3901 /* remember that a space at the end of a row doesnt count
3902 * when calculating the fill */
3903 if (cursor.pos < RowLast(row) ||
3904 !cursor.par->IsLineSeparator(cursor.pos)) {
3905 row->fill += SingleWidth(cursor.par, cursor.pos);
3908 /* some special code when deleting a newline. This is similar
3909 * to the behavior when pasting paragraphs */
3910 if (cursor.pos && cursor.par->IsNewline(cursor.pos)) {
3911 cursor.par->Erase(cursor.pos);
3912 // refresh the positions
3914 while (tmprow->next && tmprow->next->par == row->par) {
3915 tmprow = tmprow->next;
3918 if (cursor.par->IsLineSeparator(cursor.pos - 1))
3921 if (cursor.pos < cursor.par->Last() && !cursor.par->IsSeparator(cursor.pos)) {
3922 cursor.par->InsertChar(cursor.pos, ' ');
3923 // refresh the positions
3925 while (tmprow->next && tmprow->next->par == row->par) {
3926 tmprow = tmprow->next;
3931 cursor.par->Erase(cursor.pos);
3933 // refresh the positions
3935 while (tmprow->next && tmprow->next->par == row->par) {
3936 tmprow = tmprow->next;
3940 #ifndef FIX_DOUBLE_SPACE
3941 // delete superfluous blanks
3942 if (cursor.pos < cursor.par->Last() - 1 &&
3943 (cursor.par->IsLineSeparator(cursor.pos))) {
3945 if (cursor.pos == BeginningOfMainBody(cursor.par)
3947 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
3948 cursor.par->Erase(cursor.pos);
3949 // refresh the positions
3951 while (tmprow->next &&
3952 tmprow->next->par == row->par) {
3953 tmprow = tmprow->next;
3956 if (cursor.pos) // move one character left
3962 // delete newlines at the beginning of paragraphs
3963 while (cursor.par->Last() &&
3964 cursor.par->IsNewline(cursor.pos) &&
3965 cursor.pos == BeginningOfMainBody(cursor.par)) {
3966 cursor.par->Erase(cursor.pos);
3967 // refresh the positions
3969 while (tmprow->next &&
3970 tmprow->next->par == row->par) {
3971 tmprow = tmprow->next;
3977 // is there a break one row above
3978 if (row->previous && row->previous->par == row->par) {
3979 z = NextBreakPoint(row->previous, paperwidth);
3980 if ( z >= row->pos) {
3983 tmprow = row->previous;
3985 // maybe the current row is now empty
3986 if (row->pos >= row->par->Last()) {
3991 BreakAgainOneRow(row);
3992 if (row->next && row->next->par == row->par)
3993 need_break_row = row->next;
3998 // set the dimensions of the row above
3999 y -= tmprow->height;
4000 tmprow->fill = Fill(tmprow, paperwidth);
4001 SetHeightOfRow(tmprow);
4004 refresh_row = tmprow;
4005 status = LyXText::NEED_MORE_REFRESH;
4006 current_font = rawtmpfont;
4007 real_current_font = realtmpfont;
4008 SetCursor(cursor.par, cursor.pos, false);
4009 // check, whether the last character's font has changed.
4010 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
4011 if (rawparfont != rawtmpfont)
4012 RedoHeightOfParagraph(cursor);
4017 // break the cursor row again
4018 z = NextBreakPoint(row, paperwidth);
4020 if (z != RowLast(row) ||
4021 (row->next && row->next->par == row->par &&
4022 RowLast(row) == row->par->Last() - 1)){
4024 /* it can happen that a paragraph loses one row
4025 * without a real breakup. This is when a word
4026 * is to long to be broken. Well, I don t care this
4028 if (row->next && row->next->par == row->par &&
4029 RowLast(row) == row->par->Last() - 1)
4030 RemoveRow(row->next);
4034 status = LyXText::NEED_MORE_REFRESH;
4036 BreakAgainOneRow(row);
4037 current_font = rawtmpfont;
4038 real_current_font = realtmpfont;
4039 SetCursor(cursor.par, cursor.pos, false);
4040 // cursor MUST be in row now
4042 if (row->next && row->next->par == row->par)
4043 need_break_row = row->next;
4047 // set the dimensions of the row
4048 row->fill = Fill(row, paperwidth);
4049 int tmpheight = row->height;
4050 SetHeightOfRow(row);
4051 if (tmpheight == row->height)
4052 status = LyXText::NEED_VERY_LITTLE_REFRESH;
4054 status = LyXText::NEED_MORE_REFRESH;
4057 current_font = rawtmpfont;
4058 real_current_font = realtmpfont;
4059 SetCursor(cursor.par, cursor.pos, false);
4063 // restore the current font
4064 // That is what a user expects!
4065 current_font = rawtmpfont;
4066 real_current_font = realtmpfont;
4068 // check, wether the last characters font has changed.
4069 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
4070 if (rawparfont != rawtmpfont) {
4071 RedoHeightOfParagraph(cursor);
4073 // now the special right address boxes
4074 if (textclasslist.Style(parameters->textclass,
4075 cursor.par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
4076 RedoDrawingOfParagraph(cursor);
4083 void LyXText::GetVisibleRow(int offset,
4084 Row * row_ptr, long y)
4086 /* returns a printed row */
4087 Painter & pain = owner_->painter();
4089 LyXDirection direction = row_ptr->par->getParDirection();
4090 LyXParagraph::size_type vpos, pos, pos_end;
4092 int y_top, y_bottom;
4093 float fill_separator, fill_hfill, fill_label_hfill;
4094 LyXParagraph * par, * firstpar;
4097 if (row_ptr->height <= 0) {
4098 lyxerr << "LYX_ERROR: row.height: " << row_ptr->height << endl;
4101 PrepareToPrint(row_ptr, x, fill_separator,
4102 fill_hfill, fill_label_hfill);
4104 /* initialize the pixmap */
4106 pain.fillRectangle(0, offset, paperwidth, row_ptr->height);
4108 // check for NOT FAST SELECTION
4109 if (!fast_selection && !mono_video && selection) {
4110 /* selection code */
4111 if (sel_start_cursor.row == row_ptr &&
4112 sel_end_cursor.row == row_ptr) {
4113 if (sel_start_cursor.x < sel_end_cursor.x)
4114 pain.fillRectangle(sel_start_cursor.x, offset,
4115 sel_end_cursor.x - sel_start_cursor.x,
4119 pain.fillRectangle(sel_end_cursor.x, offset,
4120 sel_start_cursor.x - sel_end_cursor.x,
4124 else if (sel_start_cursor.row == row_ptr) {
4125 if (direction == LYX_DIR_LEFT_TO_RIGHT)
4126 pain.fillRectangle(sel_start_cursor.x, offset,
4127 paperwidth - sel_start_cursor.x,
4131 pain.fillRectangle(0, offset,
4135 } else if (sel_end_cursor.row == row_ptr) {
4136 if (direction == LYX_DIR_LEFT_TO_RIGHT)
4137 pain.fillRectangle(0, offset,
4142 pain.fillRectangle(sel_end_cursor.x, offset,
4143 paperwidth - sel_end_cursor.x,
4147 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
4148 pain.fillRectangle(0, offset,
4149 paperwidth, row_ptr->height,
4152 } // end of NOT FAST SELECTION code
4154 if (row_ptr->par->appendix){
4155 pain.line(1, offset,
4156 1, offset + row_ptr->height,
4157 LColor::appendixline);
4158 pain.line(paperwidth - 2, offset,
4159 paperwidth - 2, offset + row_ptr->height,
4160 LColor::appendixline);
4163 if (row_ptr->par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4164 /* draw a marker at the left margin! */
4165 LyXFont font = GetFont(row_ptr->par, 0);
4166 int asc = font.maxAscent();
4167 int x = (LYX_PAPER_MARGIN - font.width('|')) / 2;
4168 int y1 = (offset + row_ptr->baseline);
4169 int y2 = (offset + row_ptr->baseline) - asc;
4170 pain.line(x, y1, x, y2, LColor::minipageline);
4172 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4173 LyXFont font(LyXFont::ALL_SANE);
4174 font.setSize(LyXFont::SIZE_FOOTNOTE);
4175 font.setColor(LColor::footnote);
4177 int box_x = LYX_PAPER_MARGIN;
4178 box_x += font.textWidth(" wide-tab ", 10);
4179 if (row_ptr->previous &&
4180 row_ptr->previous->par->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
4182 switch (row_ptr->par->footnotekind) {
4183 case LyXParagraph::MARGIN:
4186 case LyXParagraph::FIG:
4189 case LyXParagraph::TAB:
4192 case LyXParagraph::WIDE_FIG:
4195 case LyXParagraph::WIDE_TAB:
4198 case LyXParagraph::ALGORITHM:
4201 case LyXParagraph::FOOTNOTE:
4207 // Determine background color.
4208 gc_type back = gc_lighted;
4213 pain.fillRectangle(LYX_PAPER_MARGIN,
4215 box_x - LYX_PAPER_MARGIN,
4216 int(font.maxAscent()
4217 + font.maxDescent()),
4218 LColor::footnotebg);
4220 pain.line(LYX_PAPER_MARGIN, offset,
4221 paperwidth - LYX_PAPER_MARGIN, offset,
4222 LColor::footnoteframe);
4224 pain.text(LYX_PAPER_MARGIN,
4225 offset + int(font.maxAscent()) + 1,
4228 pain.line(LYX_PAPER_MARGIN, offset,
4230 offset + int(font.maxAscent()
4231 + font.maxDescent()),
4232 LColor::footnoteframe);
4234 pain.line(LYX_PAPER_MARGIN,
4235 offset + int(font.maxAscent()
4236 + font.maxDescent()) + 1,
4238 offset + int(font.maxAscent()
4239 + font.maxDescent()) + 1,
4240 LColor::footnoteframe);
4244 /* draw the open floats in a red box */
4245 pain.line(box_x, offset,
4246 box_x, offset + row_ptr->height,
4247 LColor::footnoteframe);
4249 pain.line(paperwidth - LYX_PAPER_MARGIN,
4251 paperwidth - LYX_PAPER_MARGIN,
4252 offset + row_ptr->height,
4253 LColor::footnoteframe);
4255 if (row_ptr->previous &&
4256 row_ptr->previous->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4257 LyXFont font(LyXFont::ALL_SANE);
4258 font.setSize(LyXFont::SIZE_FOOTNOTE);
4260 int box_x = LYX_PAPER_MARGIN;
4261 box_x += font.textWidth(" wide-tab ", 10);
4263 pain.line(box_x, offset,
4264 paperwidth - LYX_PAPER_MARGIN,
4265 offset, LColor::footnote);
4269 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
4270 row_ptr->par->GetLayout());
4271 firstpar = row_ptr->par->FirstPhysicalPar();
4274 y_bottom = row_ptr->height;
4276 /* is it a first row? */
4277 if (row_ptr->pos == 0
4278 && row_ptr->par == firstpar) {
4280 /* start of appendix? */
4281 if (row_ptr->par->start_of_appendix){
4282 pain.line(1, offset,
4283 paperwidth - 2, offset,
4284 LColor::appendixline);
4287 /* think about the margins */
4288 if (!row_ptr->previous)
4289 y_top += LYX_PAPER_MARGIN;
4291 if (row_ptr->par->pagebreak_top){ /* draw a top pagebreak */
4292 pain.line(0, offset + y_top + 2 * DefaultHeight(),
4294 offset + y_top + 2 * DefaultHeight(),
4295 LColor::pagebreak, Painter::line_onoffdash);
4296 y_top += 3 * DefaultHeight();
4299 if (row_ptr->par->added_space_top.kind() == VSpace::VFILL) {
4300 /* draw a vfill top */
4301 pain.line(0, offset + 2 + y_top,
4302 LYX_PAPER_MARGIN, offset + 2 + y_top,
4305 pain.line(0, offset + y_top + 3 * DefaultHeight(),
4307 offset + y_top + 3 * DefaultHeight(),
4310 pain.line(LYX_PAPER_MARGIN / 2, offset + 2 + y_top,
4311 LYX_PAPER_MARGIN / 2,
4312 offset + y_top + 3 * DefaultHeight(),
4315 y_top += 3 * DefaultHeight();
4318 /* think about user added space */
4319 y_top += int(row_ptr->par->added_space_top.inPixels());
4321 /* think about the parskip */
4322 /* some parskips VERY EASY IMPLEMENTATION */
4323 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
4324 if (layout.latextype == LATEX_PARAGRAPH
4325 && firstpar->GetDepth() == 0
4326 && firstpar->Previous())
4327 y_top += parameters->getDefSkip().inPixels();
4328 else if (firstpar->Previous()
4329 && textclasslist.Style(parameters->textclass,
4330 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
4331 && firstpar->Previous()->GetDepth() == 0)
4332 // is it right to use defskip here, too? (AS)
4333 y_top += parameters->getDefSkip().inPixels();
4336 if (row_ptr->par->line_top) { /* draw a top line */
4337 y_top += GetFont(row_ptr->par, 0).ascent('x');
4339 pain.line(0, offset + y_top,
4340 paperwidth, offset + y_top,
4342 Painter::line_solid,
4343 Painter::line_thick);
4345 y_top += GetFont(row_ptr->par, 0).ascent('x');
4348 /* should we print a label? */
4349 if (layout.labeltype >= LABEL_STATIC
4350 && (layout.labeltype != LABEL_STATIC
4351 || layout.latextype != LATEX_ENVIRONMENT
4352 || row_ptr->par->IsFirstInSequence())) {
4353 font = GetFont(row_ptr->par, -2);
4354 if (!row_ptr->par->GetLabestring().empty()) {
4356 string tmpstring = row_ptr->par->GetLabestring();
4358 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
4359 if (parameters->secnumdepth >= 0){
4360 /* this is special code for the chapter layout. This is printed in
4361 * an extra row and has a pagebreak at the top. */
4362 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue())
4363 + int(layout.parsep) * DefaultHeight();
4364 if (direction == LYX_DIR_RIGHT_TO_LEFT)
4365 tmpx = paperwidth - LeftMargin(row_ptr) -
4366 font.stringWidth(tmpstring);
4367 pain.text(int(tmpx),
4368 offset + row_ptr->baseline - row_ptr->ascent_of_text - maxdesc,
4372 if (direction == LYX_DIR_LEFT_TO_RIGHT)
4373 tmpx = x - font.stringWidth(layout.labelsep)
4374 - font.stringWidth(tmpstring);
4376 tmpx = paperwidth - LeftMargin(row_ptr)
4377 + font.stringWidth(layout.labelsep);
4378 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4379 LyXFont font(LyXFont::ALL_SANE);
4380 font.setSize(LyXFont::SIZE_SMALL);
4381 tmpx += font.textWidth("Mwide-figM", 10);
4385 pain.text(int(tmpx),
4386 offset + row_ptr->baseline,
4390 /* the labels at the top of an environment. More or less for bibliography */
4391 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
4392 layout.labeltype == LABEL_BIBLIO ||
4393 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
4394 if (row_ptr->par->IsFirstInSequence()) {
4395 font = GetFont(row_ptr->par, -2);
4396 if (!row_ptr->par->GetLabestring().empty()) {
4397 string tmpstring = row_ptr->par->GetLabestring();
4399 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue()
4400 + (layout.labelbottomsep * DefaultHeight()));
4403 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
4404 tmpx = ( ((direction == LYX_DIR_LEFT_TO_RIGHT)
4405 ? x : LeftMargin(row_ptr) )
4406 + paperwidth - RightMargin(row_ptr) ) / 2;
4407 tmpx -= (font.stringWidth(tmpstring)/2);
4408 } else if (direction == LYX_DIR_RIGHT_TO_LEFT)
4409 tmpx = paperwidth - LeftMargin(row_ptr) -
4410 font.stringWidth(tmpstring);
4411 pain.text(int(tmpx),
4412 offset + row_ptr->baseline
4413 - row_ptr->ascent_of_text
4419 if (layout.labeltype == LABEL_BIBLIO) { // ale970302
4420 if (row_ptr->par->bibkey) {
4421 font = GetFont(row_ptr->par, -1);
4422 if (direction == LYX_DIR_LEFT_TO_RIGHT)
4423 tmpx = x - font.stringWidth(layout.labelsep)
4424 - row_ptr->par->bibkey->width(owner_->painter(), font);
4426 tmpx = paperwidth - LeftMargin(row_ptr)
4427 + font.stringWidth(layout.labelsep);
4428 row_ptr->par->bibkey->draw(owner_->painter(),
4430 offset + row_ptr->baseline,
4436 /* is it a last row? */
4437 par = row_ptr->par->LastPhysicalPar();
4438 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
4439 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
4441 /* think about the margins */
4443 y_bottom -= LYX_PAPER_MARGIN;
4445 /* draw a bottom pagebreak */
4446 if (firstpar->pagebreak_bottom) {
4447 pain.line(0, offset + y_bottom - 2 * DefaultHeight(),
4449 offset + y_bottom - 2 * DefaultHeight(),
4451 y_bottom -= 3 * DefaultHeight();
4454 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
4455 /* draw a vfill bottom */
4456 pain.line(0, offset + y_bottom - 3 * DefaultHeight(),
4458 offset + y_bottom - 3 * DefaultHeight(),
4460 pain.line(0, offset + y_bottom - 2,
4462 offset + y_bottom - 2,
4464 pain.line(LYX_PAPER_MARGIN / 2,
4465 offset + y_bottom - 3 * DefaultHeight(),
4466 LYX_PAPER_MARGIN / 2,
4467 offset + y_bottom - 2,
4469 y_bottom -= 3* DefaultHeight();
4472 /* think about user added space */
4473 y_bottom -= int(firstpar->added_space_bottom.inPixels());
4475 if (firstpar->line_bottom) {
4476 /* draw a bottom line */
4477 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
4478 pain.line(0, offset + y_bottom,
4479 paperwidth, offset + y_bottom,
4480 LColor::topline, Painter::line_solid,
4481 Painter::line_thick);
4482 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
4486 /* draw the text in the pixmap */
4487 pos_end = RowLast(row_ptr);
4489 vpos = row_ptr->pos;
4490 /* table stuff -- begin*/
4491 if (row_ptr->par->table) {
4493 int cell = NumberOfCell(row_ptr->par, row_ptr->pos);
4495 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
4497 while (vpos <= pos_end) {
4498 pos = vis2log(vpos);
4499 if (row_ptr->par->IsNewline(pos)) {
4501 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
4502 /* draw the table lines, still very simple */
4503 on_off = !row_ptr->par->table->TopLine(cell);
4505 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
4506 !row_ptr->par->table->IsContRow(cell))
4507 pain.line(int(x_old),
4508 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4510 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4512 on_off ? Painter::line_onoffdash : Painter::line_solid);
4514 on_off = !row_ptr->par->table->BottomLine(cell);
4515 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
4516 row_ptr->par->table->VeryLastRow(cell))
4518 pain.line(int(x_old),
4519 offset + y_bottom - 1,
4521 offset + y_bottom - 1,
4523 on_off ? Painter::line_onoffdash : Painter::line_solid);
4525 on_off = !row_ptr->par->table->LeftLine(cell);
4527 pain.line(int(x_old),
4528 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4530 offset + y_bottom - 1,
4532 on_off ? Painter::line_onoffdash : Painter::line_solid);
4534 on_off = !row_ptr->par->table->RightLine(cell);
4536 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
4537 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4538 int(x) - row_ptr->par->table->AdditionalWidth(cell),
4539 offset + y_bottom - 1,
4541 on_off ? Painter::line_onoffdash : Painter::line_solid);
4544 /* take care about the alignment and other spaces */
4546 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
4547 if (row_ptr->par->table->IsFirstCell(cell))
4548 --cell; // little hack, sorry
4550 } else if (row_ptr->par->IsHfill(pos)) {
4554 offset + row_ptr->baseline - DefaultHeight() / 2,
4556 offset + row_ptr->baseline,
4562 if (row_ptr->par->IsSeparator(pos)) {
4564 x+= SingleWidth(row_ptr->par, pos);
4565 /* -------> Only draw protected spaces when not in
4566 * free-spacing mode. */
4567 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
4568 pain.line(int(tmpx),
4569 offset + row_ptr->baseline - 3,
4571 offset + row_ptr->baseline - 1,
4574 pain.line(int(tmpx),
4575 offset + row_ptr->baseline - 1,
4577 offset + row_ptr->baseline - 1,
4580 pain.line(int(x - 2),
4581 offset + row_ptr->baseline - 3,
4583 offset + row_ptr->baseline - 1,
4586 /* what about underbars? */
4587 font = GetFont(row_ptr->par, pos);
4588 if (font.underbar() == LyXFont::ON
4589 && font.latex() != LyXFont::ON) {
4590 pain.line(int(tmpx),
4591 offset + row_ptr->baseline + 2,
4593 offset + row_ptr->baseline + 2);
4598 draw(row_ptr, vpos, offset, x);
4602 /* do not forget the very last cell. This has no NEWLINE so
4603 * ignored by the code above*/
4604 if (cell == row_ptr->par->table->GetNumberOfCells()-1){
4605 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
4606 on_off = !row_ptr->par->table->TopLine(cell);
4608 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
4609 !row_ptr->par->table->IsContRow(cell))
4611 pain.line(int(x_old),
4612 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4614 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4616 on_off ? Painter::line_onoffdash : Painter::line_solid);
4617 on_off = !row_ptr->par->table->BottomLine(cell);
4618 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
4619 row_ptr->par->table->VeryLastRow(cell))
4621 pain.line(int(x_old),
4622 offset + y_bottom - 1,
4624 offset + y_bottom - 1,
4626 on_off ? Painter::line_onoffdash : Painter::line_solid);
4628 on_off = !row_ptr->par->table->LeftLine(cell);
4630 pain.line(int(x_old),
4631 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4633 offset + y_bottom - 1,
4635 on_off ? Painter::line_onoffdash : Painter::line_solid);
4637 on_off = !row_ptr->par->table->RightLine(cell);
4639 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
4640 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4641 int(x) - row_ptr->par->table->AdditionalWidth(cell),
4642 offset + y_bottom - 1,
4644 on_off ? Painter::line_onoffdash : Painter::line_solid);
4647 /* table stuff -- end*/
4648 LyXParagraph::size_type main_body =
4649 BeginningOfMainBody(row_ptr->par);
4650 if (main_body > 0 &&
4651 (main_body-1 > pos_end ||
4652 !row_ptr->par->IsLineSeparator(main_body-1)))
4655 while (vpos <= pos_end) {
4656 pos = vis2log(vpos);
4657 if (main_body > 0 && pos == main_body-1) {
4658 x += fill_label_hfill
4659 + GetFont(row_ptr->par, -2).stringWidth(layout.labelsep)
4660 - SingleWidth(row_ptr->par, main_body-1);
4663 if (row_ptr->par->IsHfill(pos)) {
4666 offset + row_ptr->baseline - DefaultHeight() / 2,
4668 offset + row_ptr->baseline,
4671 if (HfillExpansion(row_ptr, pos)) {
4672 if (pos >= main_body) {
4674 offset + row_ptr->baseline - DefaultHeight() / 4,
4675 int(x + fill_hfill),
4676 offset + row_ptr->baseline - DefaultHeight() / 4,
4678 Painter::line_onoffdash);
4682 offset + row_ptr->baseline - DefaultHeight() / 4,
4683 int(x + fill_label_hfill),
4684 offset + row_ptr->baseline - DefaultHeight() / 4,
4686 Painter::line_onoffdash);
4688 x += fill_label_hfill;
4691 offset + row_ptr->baseline - DefaultHeight() / 2,
4693 offset + row_ptr->baseline,
4699 if (row_ptr->par->IsSeparator(pos)) {
4701 x+= SingleWidth(row_ptr->par, pos);
4702 if (pos >= main_body)
4704 /* -------> Only draw protected spaces when not in
4705 * free-spacing mode. */
4706 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
4708 pain.line(int(tmpx),
4709 offset + row_ptr->baseline - 3,
4711 offset + row_ptr->baseline - 1,
4714 pain.line(int(tmpx),
4715 offset + row_ptr->baseline - 1,
4717 offset + row_ptr->baseline - 1,
4720 pain.line(int(x - 2),
4721 offset + row_ptr->baseline - 3,
4723 offset + row_ptr->baseline - 1,
4726 /* what about underbars? */
4727 font = GetFont(row_ptr->par, pos);
4728 if (font.underbar() == LyXFont::ON
4729 && font.latex() != LyXFont::ON) {
4730 pain.line(int(tmpx),
4731 offset + row_ptr->baseline + 2,
4733 offset + row_ptr->baseline + 2);
4738 draw(row_ptr, vpos, offset, x);
4743 // check for FAST SELECTION
4744 if (fast_selection || mono_video) {
4747 /* selection code */
4748 if (sel_start_cursor.row == row_ptr && sel_end_cursor.row == row_ptr) {
4749 scr.fillRectangle(gc_select, sel_start_cursor.x, offset,
4750 sel_end_cursor.x - sel_start_cursor.x,
4752 } else if (sel_start_cursor.row == row_ptr) {
4753 scr.fillRectangle(gc_select, sel_start_cursor.x, offset,
4754 paperwidth - sel_start_cursor.x,
4756 } else if (sel_end_cursor.row == row_ptr) {
4757 scr.fillRectangle(gc_select, 0, offset,
4760 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
4761 scr.fillRectangle(gc_select, 0, offset,
4762 paperwidth, row_ptr->height);
4767 // end of FAST SELECTION code
4772 void LyXText::GetVisibleRow(LyXScreen & scr, int offset,
4773 Row * row_ptr, long y)
4775 /* returns a printed row */
4776 LyXDirection direction = row_ptr->par->getParDirection();
4777 LyXParagraph::size_type vpos, pos, pos_end;
4779 int y_top, y_bottom;
4780 float fill_separator, fill_hfill, fill_label_hfill;
4781 LyXParagraph * par, * firstpar;
4784 if (row_ptr->height <= 0) {
4785 lyxerr << "LYX_ERROR: row.height: " << row_ptr->height << endl;
4788 PrepareToPrint(row_ptr, x, fill_separator,
4789 fill_hfill, fill_label_hfill);
4791 /* initialize the pixmap */
4793 scr.fillRectangle(gc_clear,
4794 0, offset, paperwidth, row_ptr->height);
4795 // check for NOT FAST SELECTION
4796 if (!fast_selection && !mono_video && selection) {
4797 /* selection code */
4798 if (sel_start_cursor.row == row_ptr &&
4799 sel_end_cursor.row == row_ptr) {
4800 if (sel_start_cursor.x < sel_end_cursor.x)
4801 scr.fillRectangle(gc_selection, sel_start_cursor.x,
4803 sel_end_cursor.x - sel_start_cursor.x,
4806 scr.fillRectangle(gc_selection, sel_end_cursor.x,
4808 sel_start_cursor.x - sel_end_cursor.x,
4811 else if (sel_start_cursor.row == row_ptr) {
4812 if (direction == LYX_DIR_LEFT_TO_RIGHT)
4813 scr.fillRectangle(gc_selection, sel_start_cursor.x,
4815 paperwidth - sel_start_cursor.x,
4818 scr.fillRectangle(gc_selection, 0, offset,
4819 sel_start_cursor.x, row_ptr->height);
4820 } else if (sel_end_cursor.row == row_ptr) {
4821 if (direction == LYX_DIR_LEFT_TO_RIGHT)
4822 scr.fillRectangle(gc_selection, 0, offset,
4823 sel_end_cursor.x, row_ptr->height);
4825 scr.fillRectangle(gc_selection, sel_end_cursor.x,
4827 paperwidth - sel_end_cursor.x,
4829 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
4830 scr.fillRectangle(gc_selection, 0, offset,
4831 paperwidth, row_ptr->height);
4834 } // end of NOT FAST SELECTION code
4836 if (row_ptr->par->appendix){
4837 scr.drawVerticalLine(gc_math, 1, offset, offset+row_ptr->height);
4838 scr.drawVerticalLine(gc_math, paperwidth-2 , offset, offset+row_ptr->height);
4841 if (row_ptr->par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4842 /* draw a marker at the left margin! */
4843 LyXFont font = GetFont(row_ptr->par, 0);
4844 int asc = font.maxAscent();
4845 int x = (LYX_PAPER_MARGIN - font.width('|')) / 2;
4846 int y1 = (offset + row_ptr->baseline);
4847 int y2 = (offset + row_ptr->baseline) - asc;
4849 scr.drawVerticalLine(gc_minipage, x, y1, y2);
4851 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4852 LyXFont font(LyXFont::ALL_SANE);
4853 font.setSize(LyXFont::SIZE_FOOTNOTE);
4855 font.setColor(LColor::footnote);
4857 font.setColor(LyXFont::RED);
4860 int box_x = LYX_PAPER_MARGIN;
4861 box_x += font.textWidth(" wide-tab ", 10);
4862 if (row_ptr->previous &&
4863 row_ptr->previous->par->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
4865 switch (row_ptr->par->footnotekind) {
4866 case LyXParagraph::MARGIN:
4869 case LyXParagraph::FIG:
4872 case LyXParagraph::TAB:
4875 case LyXParagraph::WIDE_FIG:
4878 case LyXParagraph::WIDE_TAB:
4881 case LyXParagraph::ALGORITHM:
4884 case LyXParagraph::FOOTNOTE:
4889 // Determine background color.
4890 gc_type back = gc_lighted;
4894 scr.fillRectangle(back, LYX_PAPER_MARGIN, offset+1,
4895 box_x - LYX_PAPER_MARGIN,
4896 int(font.maxAscent())+
4897 int(font.maxDescent()));
4899 scr.drawLine(gc_foot,
4902 paperwidth - 2*LYX_PAPER_MARGIN);
4904 scr.drawString(font, fs,
4905 offset + int(font.maxAscent())+1,
4907 scr.drawVerticalLine(gc_foot,
4911 + int(font.maxAscent())+
4912 int(font.maxDescent()));
4914 scr.drawLine(gc_foot,
4916 + int(font.maxAscent())
4917 + int(font.maxDescent()) + 1,
4918 LYX_PAPER_MARGIN, box_x - LYX_PAPER_MARGIN);
4921 /* draw the open floats in a red box */
4922 scr.drawVerticalLine(gc_foot,
4924 offset, offset + row_ptr->height);
4926 scr.drawVerticalLine(gc_foot,
4927 paperwidth - LYX_PAPER_MARGIN,
4929 offset + row_ptr->height);
4932 if (row_ptr->previous &&
4933 row_ptr->previous->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
4934 LyXFont font(LyXFont::ALL_SANE);
4935 font.setSize(LyXFont::SIZE_FOOTNOTE);
4937 int box_x = LYX_PAPER_MARGIN;
4938 box_x += font.textWidth(" wide-tab ", 10);
4940 scr.drawLine(gc_foot,
4943 paperwidth - LYX_PAPER_MARGIN - box_x);
4947 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
4948 row_ptr->par->GetLayout());
4949 firstpar = row_ptr->par->FirstPhysicalPar();
4952 y_bottom = row_ptr->height;
4954 /* is it a first row? */
4955 if (row_ptr->pos == 0
4956 && row_ptr->par == firstpar) {
4958 /* start of appendix? */
4959 if (row_ptr->par->start_of_appendix){
4960 scr.drawLine(gc_math,
4965 /* think about the margins */
4966 if (!row_ptr->previous)
4967 y_top += LYX_PAPER_MARGIN;
4969 if (row_ptr->par->pagebreak_top){ /* draw a top pagebreak */
4970 scr.drawOnOffLine(offset + y_top + 2 * DefaultHeight(),
4972 y_top += 3 * DefaultHeight();
4975 if (row_ptr->par->added_space_top.kind() == VSpace::VFILL) {
4976 /* draw a vfill top */
4977 scr.drawLine(gc_fill,
4979 0, LYX_PAPER_MARGIN);
4980 scr.drawLine(gc_fill,
4981 offset + y_top + 3 * DefaultHeight(),
4982 0, LYX_PAPER_MARGIN);
4983 scr.drawVerticalOnOffLine(LYX_PAPER_MARGIN / 2,
4985 offset + y_top + 3 *
4988 y_top += 3 * DefaultHeight();
4991 /* think about user added space */
4992 y_top += int(row_ptr->par->added_space_top.inPixels());
4994 /* think about the parskip */
4995 /* some parskips VERY EASY IMPLEMENTATION */
4996 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
4997 if (layout.latextype == LATEX_PARAGRAPH
4998 && firstpar->GetDepth() == 0
4999 && firstpar->Previous())
5000 y_top += parameters->getDefSkip().inPixels();
5001 else if (firstpar->Previous()
5002 && textclasslist.Style(parameters->textclass,
5003 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
5004 && firstpar->Previous()->GetDepth() == 0)
5005 // is it right to use defskip here, too? (AS)
5006 y_top += parameters->getDefSkip().inPixels();
5009 if (row_ptr->par->line_top) { /* draw a top line */
5010 y_top += GetFont(row_ptr->par, 0).ascent('x');
5012 scr.drawThickLine(offset + y_top,
5014 y_top += GetFont(row_ptr->par, 0).ascent('x');
5017 /* should we print a label? */
5018 if (layout.labeltype >= LABEL_STATIC
5019 && (layout.labeltype != LABEL_STATIC
5020 || layout.latextype != LATEX_ENVIRONMENT
5021 || row_ptr->par->IsFirstInSequence())) {
5022 font = GetFont(row_ptr->par, -2);
5023 if (!row_ptr->par->GetLabestring().empty()) {
5025 string tmpstring = row_ptr->par->GetLabestring();
5027 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
5028 if (parameters->secnumdepth >= 0){
5029 /* this is special code for the chapter layout. This is printed in
5030 * an extra row and has a pagebreak at the top. */
5031 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue())
5032 + int(layout.parsep) * DefaultHeight();
5033 if (direction == LYX_DIR_RIGHT_TO_LEFT)
5034 tmpx = paperwidth - LeftMargin(row_ptr) -
5035 font.stringWidth(tmpstring);
5036 scr.drawString(font, tmpstring,
5037 offset + row_ptr->baseline
5038 - row_ptr->ascent_of_text - maxdesc,
5042 if (direction == LYX_DIR_LEFT_TO_RIGHT)
5043 tmpx = x - font.stringWidth(layout.labelsep)
5044 - font.stringWidth(tmpstring);
5046 tmpx = paperwidth - LeftMargin(row_ptr)
5047 + font.stringWidth(layout.labelsep);
5048 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
5049 LyXFont font(LyXFont::ALL_SANE);
5050 font.setSize(LyXFont::SIZE_SMALL);
5051 tmpx += font.textWidth("Mwide-figM", 10);
5055 scr.drawString(font, tmpstring,
5056 offset + row_ptr->baseline, int(tmpx));
5059 /* the labels at the top of an environment. More or less for bibliography */
5060 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
5061 layout.labeltype == LABEL_BIBLIO ||
5062 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
5063 if (row_ptr->par->IsFirstInSequence()) {
5064 font = GetFont(row_ptr->par, -2);
5065 if (!row_ptr->par->GetLabestring().empty()) {
5066 string tmpstring = row_ptr->par->GetLabestring();
5068 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue()
5069 + (layout.labelbottomsep * DefaultHeight()));
5072 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
5073 tmpx = ( ((direction == LYX_DIR_LEFT_TO_RIGHT)
5074 ? x : LeftMargin(row_ptr) )
5075 + paperwidth - RightMargin(row_ptr) ) / 2;
5076 tmpx -= (font.stringWidth(tmpstring)/2);
5077 } else if (direction == LYX_DIR_RIGHT_TO_LEFT)
5078 tmpx = paperwidth - LeftMargin(row_ptr) -
5079 font.stringWidth(tmpstring);
5081 scr.drawString(font, tmpstring,
5082 offset + row_ptr->baseline
5083 - row_ptr->ascent_of_text - maxdesc,
5088 if (layout.labeltype == LABEL_BIBLIO) { // ale970302
5089 if (row_ptr->par->bibkey) {
5090 font = GetFont(row_ptr->par, -1);
5091 if (direction == LYX_DIR_LEFT_TO_RIGHT)
5092 tmpx = x - font.stringWidth(layout.labelsep)
5093 - row_ptr->par->bibkey->Width(font);
5095 tmpx = paperwidth - LeftMargin(row_ptr)
5096 + font.stringWidth(layout.labelsep);
5097 row_ptr->par->bibkey->Draw(font, scr,
5098 offset + row_ptr->baseline,
5104 /* is it a last row? */
5105 par = row_ptr->par->LastPhysicalPar();
5106 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
5107 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
5109 /* think about the margins */
5111 y_bottom -= LYX_PAPER_MARGIN;
5113 /* draw a bottom pagebreak */
5114 if (firstpar->pagebreak_bottom) {
5115 scr.drawOnOffLine(offset + y_bottom - 2 *
5118 y_bottom -= 3 * DefaultHeight();
5121 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
5122 /* draw a vfill bottom */
5123 scr.drawLine(gc_fill,
5124 offset + y_bottom - 3 * DefaultHeight(),
5125 0, LYX_PAPER_MARGIN);
5126 scr.drawLine(gc_fill, offset + y_bottom - 2,
5127 0, LYX_PAPER_MARGIN);
5128 scr.drawVerticalOnOffLine(LYX_PAPER_MARGIN / 2,
5129 offset + y_bottom - 3 * DefaultHeight(),
5130 offset + y_bottom - 2
5132 y_bottom -= 3* DefaultHeight();
5135 /* think about user added space */
5136 y_bottom -= int(firstpar->added_space_bottom.inPixels());
5138 if (firstpar->line_bottom) {
5139 /* draw a bottom line */
5140 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
5142 scr.drawThickLine(offset + y_bottom,
5144 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
5148 /* draw the text in the pixmap */
5149 pos_end = RowLast(row_ptr);
5151 vpos = row_ptr->pos;
5152 /* table stuff -- begin*/
5153 if (row_ptr->par->table) {
5155 int cell = NumberOfCell(row_ptr->par, row_ptr->pos);
5157 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
5159 while (vpos <= pos_end) {
5160 pos = vis2log(vpos);
5161 if (row_ptr->par->IsNewline(pos)) {
5163 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
5164 /* draw the table lines, still very simple */
5165 on_off = !row_ptr->par->table->TopLine(cell);
5167 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
5168 !row_ptr->par->table->IsContRow(cell))
5169 scr.drawTableLine(offset + row_ptr->baseline -
5170 row_ptr->ascent_of_text,
5171 int(x_old), int(x - x_old), on_off);
5172 on_off = !row_ptr->par->table->BottomLine(cell);
5173 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
5174 row_ptr->par->table->VeryLastRow(cell))
5175 scr.drawTableLine(offset + y_bottom - 1,
5176 int(x_old), int(x - x_old), on_off);
5177 on_off = !row_ptr->par->table->LeftLine(cell);
5179 scr.drawVerticalTableLine(int(x_old),
5180 offset + row_ptr->baseline -
5181 row_ptr->ascent_of_text,
5182 offset + y_bottom - 1,
5184 on_off = !row_ptr->par->table->RightLine(cell);
5186 scr.drawVerticalTableLine(int(x) -
5187 row_ptr->par->table->AdditionalWidth(cell),
5188 offset + row_ptr->baseline -
5189 row_ptr->ascent_of_text,
5190 offset + y_bottom - 1,
5193 /* take care about the alignment and other spaces */
5195 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
5196 if (row_ptr->par->table->IsFirstCell(cell))
5197 --cell; // little hack, sorry
5199 } else if (row_ptr->par->IsHfill(pos)) {
5202 scr.drawVerticalLine(gc_fill, int(x),
5203 offset + row_ptr->baseline - DefaultHeight()/2,
5204 offset + row_ptr->baseline);
5208 if (row_ptr->par->IsSeparator(pos)) {
5210 x+= SingleWidth(row_ptr->par, pos);
5211 /* -------> Only draw protected spaces when not in
5212 * free-spacing mode. */
5213 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
5214 scr.drawVerticalLine(gc_fill, int(tmpx),
5215 offset + row_ptr->baseline - 3,
5216 offset + row_ptr->baseline - 1);
5217 scr.drawLine(gc_fill,
5218 offset + row_ptr->baseline - 1,
5221 scr.drawVerticalLine(gc_fill, int(x-2),
5222 offset + row_ptr->baseline - 3,
5223 offset + row_ptr->baseline - 1);
5224 /* what about underbars? */
5225 font = GetFont(row_ptr->par, pos);
5226 if (font.underbar() == LyXFont::ON
5227 && font.latex() != LyXFont::ON) {
5228 scr.drawLine(gc_copy,
5230 row_ptr->baseline + 2,
5237 Draw(row_ptr, vpos, scr, offset, x);
5241 /* do not forget the very last cell. This has no NEWLINE so
5242 * ignored by the code above*/
5243 if (cell == row_ptr->par->table->GetNumberOfCells()-1){
5244 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
5245 on_off = !row_ptr->par->table->TopLine(cell);
5247 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
5248 !row_ptr->par->table->IsContRow(cell))
5250 scr.drawTableLine(offset + row_ptr->baseline -
5251 row_ptr->ascent_of_text,
5252 int(x_old), int(x - x_old), on_off);
5253 on_off = !row_ptr->par->table->BottomLine(cell);
5254 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
5255 row_ptr->par->table->VeryLastRow(cell))
5257 scr.drawTableLine(offset + y_bottom - 1,
5258 int(x_old), int(x - x_old), on_off);
5259 on_off = !row_ptr->par->table->LeftLine(cell);
5261 scr.drawVerticalTableLine(int(x_old),
5262 offset + row_ptr->baseline -
5263 row_ptr->ascent_of_text,
5264 offset + y_bottom - 1,
5266 on_off = !row_ptr->par->table->RightLine(cell);
5268 scr.drawVerticalTableLine(int(x) -
5269 row_ptr->par->table->AdditionalWidth(cell),
5270 offset + row_ptr->baseline -
5271 row_ptr->ascent_of_text,
5272 offset + y_bottom - 1,
5276 /* table stuff -- end*/
5277 LyXParagraph::size_type main_body =
5278 BeginningOfMainBody(row_ptr->par);
5279 if (main_body > 0 &&
5280 (main_body-1 > pos_end ||
5281 !row_ptr->par->IsLineSeparator(main_body-1)))
5284 while (vpos <= pos_end) {
5285 pos = vis2log(vpos);
5286 if (main_body > 0 && pos == main_body-1) {
5287 x += fill_label_hfill
5288 + GetFont(row_ptr->par, -2).stringWidth(layout.labelsep)
5289 - SingleWidth(row_ptr->par, main_body-1);
5292 if (row_ptr->par->IsHfill(pos)) {
5294 scr.drawVerticalLine(gc_fill, int(x),
5295 offset + row_ptr->baseline - DefaultHeight()/2,
5296 offset + row_ptr->baseline);
5297 if (HfillExpansion(row_ptr, pos)) {
5298 if (pos >= main_body) {
5299 scr.drawOnOffLine(offset + row_ptr->baseline -
5305 scr.drawOnOffLine(offset + row_ptr->baseline -
5308 int(fill_label_hfill));
5309 x += fill_label_hfill;
5311 scr.drawVerticalLine(gc_fill, int(x),
5312 offset + row_ptr->baseline -
5314 offset + row_ptr->baseline);
5319 if (row_ptr->par->IsSeparator(pos)) {
5321 x+= SingleWidth(row_ptr->par, pos);
5322 if (pos >= main_body)
5324 /* -------> Only draw protected spaces when not in
5325 * free-spacing mode. */
5326 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
5328 scr.drawVerticalLine(gc_fill, int(tmpx),
5329 offset + row_ptr->baseline - 3,
5330 offset + row_ptr->baseline - 1);
5331 scr.drawLine(gc_fill,
5332 offset + row_ptr->baseline - 1,
5335 scr.drawVerticalLine(gc_fill, int(x-2),
5336 offset + row_ptr->baseline - 3,
5337 offset + row_ptr->baseline - 1);
5338 /* what about underbars? */
5339 font = GetFont(row_ptr->par, pos);
5340 if (font.underbar() == LyXFont::ON
5341 && font.latex() != LyXFont::ON) {
5342 scr.drawLine(gc_copy,
5343 offset + row_ptr->baseline + 2,
5350 Draw(row_ptr, vpos, scr, offset, x);
5354 // check for FAST SELECTION
5355 if (fast_selection || mono_video) {
5358 /* selection code */
5359 if (sel_start_cursor.row == row_ptr && sel_end_cursor.row == row_ptr) {
5360 scr.fillRectangle(gc_select, sel_start_cursor.x, offset,
5361 sel_end_cursor.x - sel_start_cursor.x,
5363 } else if (sel_start_cursor.row == row_ptr) {
5364 scr.fillRectangle(gc_select, sel_start_cursor.x, offset,
5365 paperwidth - sel_start_cursor.x,
5367 } else if (sel_end_cursor.row == row_ptr) {
5368 scr.fillRectangle(gc_select, 0, offset,
5371 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
5372 scr.fillRectangle(gc_select, 0, offset,
5373 paperwidth, row_ptr->height);
5378 // end of FAST SELECTION code
5383 int LyXText::DefaultHeight() const
5385 LyXFont font(LyXFont::ALL_SANE);
5386 return int(font.maxAscent() + font.maxDescent() * 1.5);
5390 /* returns the column near the specified x-coordinate of the row
5391 * x is set to the real beginning of this column */
5392 int LyXText::GetColumnNearX(Row * row, int & x) const
5395 float fill_separator, fill_hfill, fill_label_hfill;
5397 PrepareToPrint(row, tmpx, fill_separator,
5398 fill_hfill, fill_label_hfill);
5400 LyXDirection direction = row->par->getParDirection();
5401 LyXParagraph::size_type vc = row->pos;
5402 LyXParagraph::size_type last = RowLast(row);
5403 LyXParagraph::size_type c;
5405 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
5406 row->par->GetLayout());
5407 /* table stuff -- begin */
5408 if (row->par->table) {
5409 if (row->next && row->next->par == row->par //the last row doesn't need a newline at the end
5410 && row->par->IsNewline(last))
5412 int cell = NumberOfCell(row->par, row->pos);
5415 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
5417 && (c = vis2log(vc)) >= 0
5418 && tmpx + (SingleWidth(row->par, c)/2) <= x
5420 if (row->par->IsNewline(c)) {
5421 if (x_old + row->par->table->WidthOfColumn(cell) <= x){
5422 tmpx = x_old + row->par->table->WidthOfColumn(cell);
5425 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
5430 tmpx += SingleWidth(row->par, c);
5435 /* table stuff -- end*/
5436 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
5437 float last_tmpx = tmpx;
5439 if (main_body > 0 &&
5440 (main_body-1 > last ||
5441 !row->par->IsLineSeparator(main_body-1)))
5444 while (vc <= last && tmpx <= x) {
5447 if (main_body > 0 && c == main_body-1) {
5448 tmpx += fill_label_hfill +
5449 GetFont(row->par, -2).stringWidth(layout.labelsep);
5450 if (row->par->IsLineSeparator(main_body-1))
5451 tmpx -= SingleWidth(row->par, main_body-1);
5454 tmpx += SingleWidth(row->par, c);
5455 if (HfillExpansion(row, c)) {
5459 tmpx += fill_label_hfill;
5461 else if (c >= main_body
5462 && row->par->IsSeparator(c)) {
5463 tmpx+= fill_separator;
5468 if (vc > row->pos && (tmpx+last_tmpx)/2 > x) {
5473 /* make sure that a last space in a row doesnt count */
5474 if (row->pos <= last
5475 && !(!row->next || row->next->par != row->par))
5476 if (direction == LYX_DIR_LEFT_TO_RIGHT && vc > last
5477 && row->par->IsLineSeparator(vis2log(last)) ) {
5479 tmpx -= fill_separator+SingleWidth(row->par, vis2log(last));
5480 } else if (direction == LYX_DIR_RIGHT_TO_LEFT
5482 && row->par->IsLineSeparator(vis2log(row->pos)) ) {
5484 tmpx += fill_separator+SingleWidth(row->par, vis2log(row->pos));
5487 if (row->pos > last) // Row is empty?
5489 else if (vc <= last) {
5491 LyXDirection direction = row->par->getLetterDirection(c);
5492 if (vc > row->pos && row->par->IsLineSeparator(c)
5493 && row->par->getLetterDirection(vis2log(vc - 1)) != direction)
5495 if (direction == LYX_DIR_RIGHT_TO_LEFT)
5498 c = vis2log(last)+1;
5499 if (row->par->getLetterDirection(c - 1) == LYX_DIR_RIGHT_TO_LEFT)
5503 if (!row->par->table && row->pos <= last && c > last
5504 && row->par->IsNewline(last)) {
5505 if (row->par->getLetterDirection(last) == LYX_DIR_LEFT_TO_RIGHT)
5506 tmpx -= SingleWidth(row->par, last);
5508 tmpx += SingleWidth(row->par, last);
5518 /* turn the selection into a new environment. If there is no selection,
5519 * create an empty environment */
5520 void LyXText::InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind)
5522 /* no footnoteenvironment in a footnoteenvironment */
5523 if (cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
5524 WriteAlert(_("Impossible operation"),
5525 _("You can't insert a float in a float!"),
5529 /* no marginpars in minipages */
5530 if (kind == LyXParagraph::MARGIN
5531 && cursor.par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
5532 WriteAlert(_("Impossible operation"),
5533 _("You can't insert a marginpar in a minipage!"),
5538 /* this doesnt make sense, if there is no selection */
5539 bool dummy_selection = false;
5541 sel_start_cursor = cursor; /* dummy selection */
5542 sel_end_cursor = cursor;
5543 dummy_selection = true;
5546 LyXParagraph *tmppar;
5548 if (sel_start_cursor.par->table || sel_end_cursor.par->table){
5549 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
5553 /* a test to make sure there is not already a footnote
5554 * in the selection. */
5556 tmppar = sel_start_cursor.par->ParFromPos(sel_start_cursor.pos);
5558 while (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos) &&
5559 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
5560 tmppar = tmppar->next;
5562 if (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)
5563 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
5564 WriteAlert(_("Impossible operation"),
5565 _("Float would include float!"),
5570 /* ok we have a selection. This is always between sel_start_cursor
5571 * and sel_end cursor */
5573 SetUndo(Undo::FINISH,
5574 sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous,
5575 sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)->next);
5577 if (sel_end_cursor.pos > 0
5578 && sel_end_cursor.par->IsLineSeparator(sel_end_cursor.pos - 1))
5579 sel_end_cursor.pos--; /* please break before a space at
5581 if (sel_start_cursor.par == sel_end_cursor.par
5582 && sel_start_cursor.pos > sel_end_cursor.pos)
5583 sel_start_cursor.pos--;
5585 sel_end_cursor.par->BreakParagraphConservative(sel_end_cursor.pos);
5587 sel_end_cursor.par = sel_end_cursor.par->Next();
5588 sel_end_cursor.pos = 0;
5590 // don't forget to insert a dummy layout paragraph if necessary
5591 if (sel_start_cursor.par->GetLayout() != sel_end_cursor.par->layout){
5592 sel_end_cursor.par->BreakParagraphConservative(0);
5593 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
5594 sel_end_cursor.par = sel_end_cursor.par->next;
5597 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
5599 cursor = sel_end_cursor;
5601 /* please break behind a space, if there is one. The space should
5603 if (sel_start_cursor.pos > 0
5604 && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1))
5605 sel_start_cursor.pos--;
5606 if (sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) {
5607 sel_start_cursor.par->Erase(sel_start_cursor.pos);
5610 sel_start_cursor.par->BreakParagraphConservative(sel_start_cursor.pos);
5611 tmppar = sel_start_cursor.par->Next();
5613 if (dummy_selection) {
5615 if (kind == LyXParagraph::TAB
5616 || kind == LyXParagraph::FIG
5617 || kind == LyXParagraph::WIDE_TAB
5618 || kind == LyXParagraph::WIDE_FIG
5619 || kind == LyXParagraph::ALGORITHM) {
5620 int lay = textclasslist.NumberOfLayout(parameters->textclass,
5622 if (lay == -1) // layout not found
5623 // use default layout "Standard" (0)
5625 tmppar->SetLayout(lay);
5629 if (sel_start_cursor.pos > 0) {
5630 /* the footnote-environment should begin with a standard layout.
5631 * Imagine you insert a footnote within an enumeration, you
5632 * certainly do not want an enumerated footnote! */
5636 /* this is a exception the user would sometimes expect, I hope */
5637 sel_start_cursor.par->Clear();
5641 while (tmppar != sel_end_cursor.par) {
5642 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
5643 tmppar->footnotekind = kind;
5644 tmppar = tmppar->Next();
5647 RedoParagraphs(sel_start_cursor, sel_end_cursor.par->Next());
5649 SetCursor(sel_start_cursor.par->Next(), 0);
5655 // returns pointer to a specified row
5656 Row * LyXText::GetRow(LyXParagraph * par,
5657 LyXParagraph::size_type pos, long & y) const
5662 if (par == currentrow->par || par == currentrow->par->Previous()) {
5663 // do not dereference par, it may have been deleted
5664 // already! (Matthias)
5665 while (currentrow->previous && currentrow->previous->par != par) {
5666 currentrow = currentrow->previous;
5667 currentrow_y -= currentrow->height;
5669 while (currentrow->previous && currentrow->previous->par == par) {
5670 currentrow = currentrow->previous;
5671 currentrow_y -= currentrow->height;
5674 tmprow = currentrow;
5676 // find the first row of the specified paragraph
5677 while (tmprow->next && (tmprow->par != par)) {
5678 y += tmprow->height;
5679 tmprow = tmprow->next;
5682 if (tmprow->par == par){
5683 // now find the wanted row
5684 while (tmprow->pos < pos && tmprow->next && tmprow->next->par == par &&
5685 tmprow->next->pos <= pos) {
5686 y += tmprow->height;
5687 tmprow = tmprow->next;
5689 currentrow = tmprow;
5696 // find the first row of the specified paragraph
5697 while (tmprow->next && (tmprow->par != par)) {
5698 y += tmprow->height;
5699 tmprow = tmprow->next;
5702 // now find the wanted row
5703 while (tmprow->pos < pos && tmprow->next && tmprow->next->par == par &&
5704 tmprow->next->pos <= pos) {
5705 y += tmprow->height;
5706 tmprow = tmprow->next;
5709 currentrow = tmprow;