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"
36 static const int LYX_PAPER_MARGIN = 20;
38 extern int mono_video;
39 extern int reverse_video;
40 extern int fast_selection;
41 extern BufferView * current_view;
44 extern int bibitemMaxWidth(LyXFont const &);
46 #define FIX_DOUBLE_SPACE 1
48 int LyXText::SingleWidth(LyXParagraph * par,
49 LyXParagraph::size_type pos) const
51 char c = par->GetChar(pos);
52 return SingleWidth(par, pos, c);
56 int LyXText::SingleWidth(LyXParagraph * par,
57 LyXParagraph::size_type pos, char c) const
59 LyXFont font = GetFont(par, pos);
61 // The most common case is handled first (Asger)
65 } else if (IsHfillChar(c)) {
66 return 3; /* Because of the representation
67 * as vertical lines */
69 } else if (c == LyXParagraph::META_FOOTNOTE ||
70 c == LyXParagraph::META_MARGIN ||
71 c == LyXParagraph::META_FIG ||
72 c == LyXParagraph::META_TAB ||
73 c == LyXParagraph::META_WIDE_FIG ||
74 c == LyXParagraph::META_WIDE_TAB ||
75 c == LyXParagraph::META_ALGORITHM)
79 case LyXParagraph::META_MARGIN:
82 case LyXParagraph::META_FIG:
85 case LyXParagraph::META_TAB:
88 case LyXParagraph::META_ALGORITHM:
91 case LyXParagraph::META_WIDE_FIG:
94 case LyXParagraph::META_WIDE_TAB:
97 case LyXParagraph::META_FOOTNOTE:
103 return font.stringWidth(fs);
106 else if (c == LyXParagraph::META_INSET) {
107 Inset *tmpinset= par->GetInset(pos);
109 return par->GetInset(pos)->Width(font);
113 } else if (IsSeparatorChar(c))
115 else if (IsNewlineChar(c))
117 return font.width(c);
121 // Returns the paragraph position of the last character in the specified row
122 LyXParagraph::size_type LyXText::RowLast(Row const * row) const
125 return row->par->Last() - 1;
126 else if (row->next->par != row->par)
127 return row->par->Last() - 1;
129 return row->next->pos - 1;
133 void LyXText::Draw(Row const * row, LyXParagraph::size_type & pos,
134 LyXScreen & scr, int offset, float & x)
136 char c = row->par->GetChar(pos);
138 if (IsNewlineChar(c)) {
140 // Draw end-of-line marker
142 LyXFont font = GetFont(row->par, pos);
143 int asc = font.maxAscent();
144 int wid = font.width('n');
145 int y = (offset + row->baseline);
147 p[0].x = int(x + wid*0.375); p[0].y = int(y - 0.875*asc*0.75);
148 p[1].x = int(x); p[1].y = int(y - 0.500*asc*0.75);
149 p[2].x = int(x + wid*0.375); p[2].y = int(y - 0.125*asc*0.75);
150 scr.drawLines(::getGC(gc_new_line), p, 3);
152 p[0].x = int(x); p[0].y = int(y - 0.500*asc*0.75);
153 p[1].x = int(x + wid); p[1].y = int(y - 0.500*asc*0.75);
154 p[2].x = int(x + wid); p[2].y = int(y - asc*0.75);
155 scr.drawLines(::getGC(gc_new_line), p, 3);
159 LyXFont font = GetFont(row->par, pos);
160 LyXFont font2 = font;
162 if (c == LyXParagraph::META_FOOTNOTE
163 || c == LyXParagraph::META_MARGIN
164 || c == LyXParagraph::META_FIG
165 || c == LyXParagraph::META_TAB
166 || c == LyXParagraph::META_WIDE_FIG
167 || c == LyXParagraph::META_WIDE_TAB
168 || c == LyXParagraph::META_ALGORITHM) {
171 case LyXParagraph::META_MARGIN:
173 // Draw a sign at the left margin!
174 scr.drawText(font, "!", 1, offset + row->baseline,
175 (LYX_PAPER_MARGIN - font.width('!'))/2);
177 case LyXParagraph::META_FIG:
180 case LyXParagraph::META_TAB:
183 case LyXParagraph::META_ALGORITHM:
186 case LyXParagraph::META_WIDE_FIG:
189 case LyXParagraph::META_WIDE_TAB:
192 case LyXParagraph::META_FOOTNOTE:
199 // calculate the position of the footnotemark
200 int y = (row->baseline - font2.maxAscent()
203 font.setColor(LyXFont::INSET);
207 // draw it and set new x position
208 x += scr.drawString(font, fs, offset + y, int(x));
210 scr.drawLine(gc_foot, offset + row->baseline,
211 int(tmpx), int(x - tmpx));
215 } else if (c == LyXParagraph::META_INSET) {
216 Inset * tmpinset = row->par->GetInset(pos);
218 tmpinset->Draw(font, scr, offset + row->baseline, x);
223 /* usual characters, no insets */
225 // Collect character that we can draw in one command
227 // This is dirty, but fast. Notice that it will never be too small.
228 // For the record, I'll note that Microsoft Word has a limit
229 // of 768 here. We have none :-) (Asger)
230 // Ok. I am the first to admit that the use of std::string will be
231 // a tiny bit slower than using a POD char array. However, I claim
232 // that this slowdown is so small that it is close to inperceptive.
233 // So IMHO we should go with the easier and clearer implementation.
234 // And even if 1024 is a large number here it might overflow, string
235 // will only overflow if the machine is out of memory...
236 static string textstring;
240 LyXParagraph::size_type last = RowLast(row);
243 && static_cast<char>(c = row->par->GetChar(pos)) > ' '
244 && font2 == GetFont(row->par, pos)) {
250 // If monochrome and LaTeX mode, provide reverse background
252 font.latex() == LyXFont::ON) {
253 int a = font.maxAscent();
254 int d = font.maxDescent();
255 scr.fillRectangle(gc_copy, int(tmpx),
256 offset + row->baseline - a,
257 font.textWidth(textstring.c_str(),
258 textstring.length()), a + d);
261 // Draw text and set the new x position
262 x += scr.drawText(font, textstring.c_str(), textstring.length(),
263 offset + row->baseline,
266 // what about underbars?
267 if (font.underbar() == LyXFont::ON && font.latex() != LyXFont::ON) {
268 scr.drawLine(gc_copy, offset + row->baseline + 2,
269 int(tmpx), int(x - tmpx));
272 // If we want ulem.sty support, drawing
273 // routines should go here. (Asger)
274 // Why shouldn't LyXFont::drawText handle it internally?
278 // Returns the left beginning of the text.
279 // This information cannot be taken from the layouts-objekt, because in
280 // LaTeX the beginning of the text fits in some cases (for example sections)
281 // exactly the label-width.
282 int LyXText::LeftMargin(Row const * row) const
284 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
285 row->par->GetLayout());
287 string parindent = layout.parindent;
289 /* table stuff -- begin */
292 /* table stuff -- end */
294 int x = LYX_PAPER_MARGIN;
296 x += textclasslist.TextClass(parameters->textclass)
298 .signedStringWidth(textclasslist
299 .TextClass(parameters->textclass)
302 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
303 LyXFont font(LyXFont::ALL_SANE);
304 font.setSize(LyXFont::SIZE_SMALL);
305 x += font.textWidth("Mwide-figM", 10) + LYX_PAPER_MARGIN/2;
308 // this is the way, LyX handles the LaTeX-Environments.
309 // I have had this idea very late, so it seems to be a
310 // later added hack and this is true
311 if (!row->par->GetDepth()) {
312 if (!row->par->GetLayout()) {
313 // find the previous same level paragraph
314 if (row->par->FirstPhysicalPar()->Previous()) {
315 LyXParagraph * newpar = row->par
316 ->DepthHook(row->par->GetDepth());
318 textclasslist.Style(parameters->textclass,
325 // find the next level paragraph
327 LyXParagraph * newpar = row->par->DepthHook(row->par->GetDepth()-1);
329 // make a corresponding row. Needed to call LeftMargin()
331 // check wether it is a sufficent paragraph
332 if (newpar && newpar->footnoteflag == row->par->footnoteflag
334 .Style(parameters->textclass,
335 newpar->GetLayout()).isEnvironment()) {
337 dummyrow.par = newpar;
338 dummyrow.pos = newpar->Last();
339 x = LeftMargin(&dummyrow);
341 // this is no longer an error, because this function
342 // is used to clear impossible depths after changing
343 // a layout. Since there is always a redo,
344 // LeftMargin() is always called
345 row->par->FirstPhysicalPar()->depth = 0;
348 if (newpar && !row->par->GetLayout()) {
349 if (newpar->FirstPhysicalPar()->noindent)
352 parindent = textclasslist
353 .Style(parameters->textclass,
354 newpar->GetLayout()).parindent;
359 LyXFont labelfont = GetFont(row->par, -2);
360 switch (layout.margintype) {
362 if (!layout.leftmargin.empty()) {
364 .TextClass(parameters->textclass)
366 .signedStringWidth(layout.leftmargin);
368 if (!row->par->GetLabestring().empty()) {
369 x += labelfont.signedStringWidth(layout.labelindent);
370 x += labelfont.stringWidth(row->par->GetLabestring());
371 x += labelfont.stringWidth(layout.labelsep);
375 x += labelfont.signedStringWidth(layout.labelindent);
376 if (row->pos >= BeginningOfMainBody(row->par)) {
377 if (!row->par->GetLabelWidthString().empty()) {
379 .stringWidth(row->par
380 ->GetLabelWidthString());
381 x += labelfont.stringWidth(layout.labelsep);
386 x += textclasslist.TextClass(parameters->textclass)
387 .defaultfont().signedStringWidth(layout.leftmargin) * 4
388 / (row->par->GetDepth() + 4);
390 case MARGIN_FIRST_DYNAMIC:
391 if (layout.labeltype == LABEL_MANUAL) {
392 if (row->pos >= BeginningOfMainBody(row->par)) {
394 .signedStringWidth(layout.leftmargin);
397 .signedStringWidth(layout.labelindent);
400 // Special case to fix problems with
402 || (layout.labeltype == LABEL_STATIC
403 && layout.latextype == LATEX_ENVIRONMENT
404 && ! row->par->IsFirstInSequence())) {
405 x += labelfont.signedStringWidth(layout.leftmargin);
406 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
407 && layout.labeltype != LABEL_BIBLIO
408 && layout.labeltype !=
409 LABEL_CENTERED_TOP_ENVIRONMENT) {
410 x += labelfont.signedStringWidth(layout.labelindent);
411 x += labelfont.stringWidth(layout.labelsep);
412 x += labelfont.stringWidth(row->par->GetLabestring());
416 case MARGIN_RIGHT_ADDRESS_BOX:
418 // ok, a terrible hack. The left margin depends on the widest
419 // row in this paragraph. Do not care about footnotes, they
420 // are *NOT* allowed in the LaTeX realisation of this layout.
422 // find the first row of this paragraph
423 Row const * tmprow = row;
424 while (tmprow->previous && tmprow->previous->par == row->par)
425 tmprow = tmprow->previous;
427 int minfill = tmprow->fill;
428 while (tmprow->next && tmprow->next->par == row->par) {
429 tmprow = tmprow->next;
430 if (tmprow->fill < minfill)
431 minfill = tmprow->fill;
434 x += textclasslist.TextClass(parameters->textclass)
435 .defaultfont().signedStringWidth(layout.leftmargin);
440 if (row->par->pextra_type == LyXParagraph::PEXTRA_INDENT) {
441 if (!row->par->pextra_widthp.empty()) {
443 atoi(row->par->pextra_widthp.c_str()) / 100;
444 } else if (!row->par->pextra_width.empty()) {
445 int xx = VSpace(row->par->pextra_width).inPixels();
448 xx = paperwidth * 80 / 100;
450 } else { // should not happen
451 LyXFont font(LyXFont::ALL_SANE);
452 x += font.stringWidth("XXXXXX");
457 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
458 align = layout.align;
460 align = row->par->FirstPhysicalPar()->align;
462 // set the correct parindent
464 if ((layout.labeltype == LABEL_NO_LABEL
465 || layout.labeltype == LABEL_TOP_ENVIRONMENT
466 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
467 || (layout.labeltype == LABEL_STATIC
468 && layout.latextype == LATEX_ENVIRONMENT
469 && ! row->par->IsFirstInSequence()))
470 && row->par == row->par->FirstPhysicalPar()
471 && align == LYX_ALIGN_BLOCK
472 && !row->par->noindent
473 && (row->par->layout ||
474 parameters->paragraph_separation ==
475 BufferParams::PARSEP_INDENT))
476 x += textclasslist.TextClass(parameters->textclass)
477 .defaultfont().stringWidth(parindent);
479 if (layout.labeltype == LABEL_BIBLIO) {
480 // ale970405 Right width for bibitems
481 x += bibitemMaxWidth(textclasslist
482 .TextClass(parameters
492 int LyXText::RightMargin(Row const * row) const
494 LyXLayout const & layout =
495 textclasslist.Style(parameters->textclass,
496 row->par->GetLayout());
498 int x = LYX_PAPER_MARGIN
500 .TextClass(parameters->textclass)
502 .signedStringWidth(textclasslist
503 .TextClass(parameters->textclass)
506 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
507 x += LYX_PAPER_MARGIN / 2;
510 // this is the way, LyX handles the LaTeX-Environments.
511 // I have had this idea very late, so it seems to be a
512 // later added hack and this is true
513 if (row->par->GetDepth()) {
514 // find the next level paragraph
516 LyXParagraph * newpar = row->par;
519 newpar = newpar->FirstPhysicalPar()->Previous();
521 newpar = newpar->FirstPhysicalPar();
522 } while (newpar && newpar->GetDepth() >= row->par->GetDepth()
523 && newpar->footnoteflag == row->par->footnoteflag);
525 // make a corresponding row. Needed to call LeftMargin()
527 // check wether it is a sufficent paragraph
528 if (newpar && newpar->footnoteflag == row->par->footnoteflag
529 && textclasslist.Style(parameters->textclass,
533 dummyrow.par = newpar;
535 x = RightMargin(&dummyrow);
537 // this is no longer an error, because this function
538 // is used to clear impossible depths after changing
539 // a layout. Since there is always a redo,
540 // LeftMargin() is always called
541 row->par->FirstPhysicalPar()->depth = 0;
545 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
546 x += textclasslist.TextClass(parameters->textclass)
548 .signedStringWidth(layout.rightmargin) * 4
549 / (row->par->GetDepth() + 4);
554 int LyXText::LabelEnd (Row const * row) const
556 if (textclasslist.Style(parameters->textclass,
557 row->par->GetLayout()).margintype
561 tmprow.pos = row->par->Last();
562 return LeftMargin(&tmprow); /* just the beginning
565 return 0; /* LabelEnd is only needed, if the
566 layout fills a flushleft
571 /* table stuff -- begin*/
572 int LyXText::NumberOfCell(LyXParagraph * par,
573 LyXParagraph::size_type pos) const
576 LyXParagraph::size_type tmp_pos = 0;
577 while (tmp_pos < pos) {
578 if (par->IsNewline(tmp_pos))
586 int LyXText::WidthOfCell(LyXParagraph * par,
587 LyXParagraph::size_type & pos) const
590 while (pos < par->Last() && !par->IsNewline(pos)) {
591 w += SingleWidth(par, pos);
594 if (par->IsNewline(pos))
600 bool LyXText::HitInTable(Row * row, int x) const
603 float fill_separator, fill_hfill, fill_label_hfill;
604 if (!row->par->table)
606 PrepareToPrint(row, tmpx, fill_separator,
607 fill_hfill, fill_label_hfill);
608 return (x > tmpx && x < tmpx + row->par->table->WidthOfTable());
612 bool LyXText::MouseHitInTable(int x, long y) const
614 Row * row = GetRowNearY(y);
615 return HitInTable(row, x);
619 /* table stuff -- end*/
622 // get the next breakpoint in a given paragraph
623 LyXParagraph::size_type
624 LyXText::NextBreakPoint(Row const * row, int width) const
626 LyXParagraph * par = row->par;
627 LyXParagraph::size_type pos = row->pos;
629 /* table stuff -- begin*/
631 while (pos < par->size()
632 && (!par->IsNewline(pos)
633 || !par->table->IsFirstCell(NumberOfCell(par, pos+1)))) {
634 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
635 par->GetInset(pos) && par->GetInset(pos)->display()){
636 par->GetInset(pos)->display(false);
642 /* table stuff -- end*/
644 // position of the last possible breakpoint
645 // -1 isn't a suitable value, but a flag
646 LyXParagraph::size_type last_separator = -1;
647 int left_margin = LabelEnd(row);
648 width -= RightMargin(row);
650 LyXParagraph::size_type main_body = BeginningOfMainBody(par);
651 LyXLayout const & layout =
652 textclasslist.Style(parameters->textclass, par->GetLayout());
653 LyXParagraph::size_type i = pos;
655 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
656 /* special code for right address boxes, only newlines count */
657 while (i < par->Last()) {
658 if (par->IsNewline(i)) {
660 i = par->Last() - 1; // this means break
662 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
663 par->GetInset(i) && par->GetInset(i)->display()){
664 par->GetInset(i)->display(false);
669 // Last position is an invariant
670 LyXParagraph::size_type const last =
672 // this is the usual handling
673 int x = LeftMargin(row);
674 while (x < width && i < last) {
675 char c = par->GetChar(i);
676 if (IsNewlineChar(c)) {
678 x = width; // this means break
679 } else if (c == LyXParagraph::META_INSET &&
680 par->GetInset(i) && par->GetInset(i)->display()){
681 // check wether a Display() inset is
682 // valid here. if not, change it to
684 if (layout.isCommand()
685 || (layout.labeltype == LABEL_MANUAL
686 && i < BeginningOfMainBody(par))){
687 // display istn't allowd
688 par->GetInset(i)->display(false);
689 x += SingleWidth(par, i, c);
691 // inset is display. So break the line here
695 if (IsLineSeparatorChar(par->GetChar(i+1)))
698 last_separator = last; // to avoid extra rows
700 last_separator = i - 1;
701 x = width; // this means break
704 if (IsLineSeparatorChar(c))
706 x += SingleWidth(par, i, c);
709 if (i == main_body) {
710 x += GetFont(par, -2).stringWidth(layout.labelsep);
711 if (par->IsLineSeparator(i - 1))
712 x-= SingleWidth(par, i - 1);
717 // end of paragraph is always a suitable separator
718 if (i == last && x < width)
722 // well, if last_separator is still 0, the line isn't breakable.
723 // don't care and cut simply at the end
724 if (last_separator < 0) {
728 // manual labels cannot be broken in LaTeX, do not care
729 if (main_body && last_separator < main_body)
730 last_separator = main_body - 1;
732 return last_separator;
736 // returns the minimum space a row needs on the screen in pixel
737 int LyXText::Fill(Row const * row, int paper_width) const
740 // get the pure distance
741 LyXParagraph::size_type last = RowLast(row);
742 /* table stuff -- begin */
743 if (row->par->table) {
744 // for tables FILL does calculate the widthes of each cell in
746 LyXParagraph::size_type pos = row->pos;
747 int cell = NumberOfCell(row->par, pos);
750 row->par->table->SetWidthOfCell(cell,
751 WidthOfCell(row->par,
754 } while (pos <= last && !row->par->table->IsFirstCell(cell));
755 // don't forget the very last table cell without characters
756 if (cell == row->par->table->GetNumberOfCells() - 1)
757 row->par->table->SetWidthOfCell(cell,
758 WidthOfCell(row->par,
761 return 0; /* width of table cannot be returned since
762 * we cannot guarantee its correct value at
765 /* table stuff -- end*/
767 int left_margin = LabelEnd(row);
769 // if the row ends with newline, this newline will not be relevant
770 if (last >= 0 && row->par->IsNewline(last))
773 // if the row ends with a space, this space will not be relevant
774 if (last >= 0 && row->par->IsLineSeparator(last))
777 // special handling of the right address boxes
778 if (textclasslist.Style(parameters->textclass,
779 row->par->GetLayout()).margintype
780 == MARGIN_RIGHT_ADDRESS_BOX) {
781 int tmpfill = row->fill;
782 row->fill = 0; // the minfill in MarginLeft()
788 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
789 row->par->GetLayout());
790 LyXParagraph::size_type main_body =
791 BeginningOfMainBody(row->par);
792 LyXParagraph::size_type i = row->pos;
794 w += SingleWidth(row->par, i);
796 if (i == main_body) {
797 w += GetFont(row->par, -2)
798 .stringWidth(layout.labelsep);
799 if (row->par->IsLineSeparator(i - 1))
800 w -= SingleWidth(row->par, i - 1);
806 fill = paper_width - w - RightMargin(row);
811 // returns the minimum space a manual label needs on the screen in pixel
812 int LyXText::LabelFill(Row const * row) const
814 LyXParagraph::size_type last = BeginningOfMainBody(row->par) - 1;
815 // -1 because a label ends either with a space that is in the label,
816 // or with the beginning of a footnote that is outside the label.
818 // I don't understand this code in depth, but sometimes "last" is
819 // less than 0 and this causes a crash. This fix seems to work
820 // correctly, but I bet the real error is elsewhere. The bug is
821 // triggered when you have an open footnote in a paragraph
822 // environment with a manual label. (Asger)
823 if (last < 0) last = 0;
825 if (row->par->IsLineSeparator(last)) /* a sepearator at this end
832 w += SingleWidth(row->par, i);
837 if (!row->par->labelwidthstring.empty()) {
838 fill = GetFont(row->par, -2)
839 .stringWidth(row->par->labelwidthstring) - w;
849 // returns the number of separators in the specified row. The separator
850 // on the very last column doesnt count
851 int LyXText::NumberOfSeparators(Row const * row) const
853 int last = RowLast(row);
855 //int main_body = BeginningOfMainBody(row->par);
858 // I think this is equivalent to the above. (Lgb)
859 int p = max(row->pos, BeginningOfMainBody(row->par));
861 for (; p < last; ++p) {
862 if (row->par->IsSeparator(p)) {
870 // returns the number of hfills in the specified row. The LyX-Hfill is
871 // a LaTeX \hfill so that the hfills at the beginning and at the end were
872 // ignored. This is *MUCH* more usefull than not to ignore!
873 int LyXText::NumberOfHfills(Row const * row) const
875 int last = RowLast(row);
876 int first = row->pos;
877 if (first) { /* hfill *DO* count at the beginning
879 while(first <= last && row->par->IsHfill(first))
883 //int main_body = BeginningOfMainBody(row->par);
884 //if (first < main_body)
885 // first = main_body;
886 // I think this is equivalent to the above. (Lgb)
887 first = max(first, BeginningOfMainBody(row->par));
889 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
890 if (row->par->IsHfill(p)) {
898 // like NumberOfHfills, but only those in the manual label!
899 int LyXText::NumberOfLabelHfills(Row const * row) const
901 LyXParagraph::size_type last = RowLast(row);
902 LyXParagraph::size_type first = row->pos;
903 if (first) { /* hfill *DO* count at the beginning
905 while(first < last && row->par->IsHfill(first))
908 //LyXParagraph::size_type main_body =
909 //BeginningOfMainBody(row->par);
910 //if (last > main_body)
912 // I think this is eqvialent to the above. (Lgb)
913 last = min(last, BeginningOfMainBody(row->par));
915 for (LyXParagraph::size_type p = first;
916 p < last; ++p) { // last, because the end is ignored!
917 if (row->par->IsHfill(p)) {
925 // returns true, if a expansion is needed.
926 // Rules are given by LaTeX
927 bool LyXText::HfillExpansion(Row const * row_ptr,
928 LyXParagraph::size_type pos) const
930 // by the way, is it a hfill?
931 if (!row_ptr->par->IsHfill(pos))
934 // at the end of a row it does not count
935 if (pos >= RowLast(row_ptr))
938 // at the beginning of a row it does not count, if it is not
939 // the first row of a paragaph
943 // in some labels it does not count
944 if (textclasslist.Style(parameters->textclass,
945 row_ptr->par->GetLayout()).margintype
947 && pos < BeginningOfMainBody(row_ptr->par))
950 // if there is anything between the first char of the row and
951 // the sepcified position that is not a newline and not a hfill,
952 // the hfill will count, otherwise not
953 LyXParagraph::size_type i = row_ptr->pos;
954 while (i < pos && (row_ptr->par->IsNewline(i)
955 || row_ptr->par->IsHfill(i)))
962 void LyXText::SetHeightOfRow(Row * row_ptr) const
964 /* get the maximum ascent and the maximum descent */
965 int asc, maxasc, desc, maxdesc, pos_end, pos, labeladdon;
967 float layoutdesc = 0;
972 /* this must not happen before the currentrow for clear reasons.
973 so the trick is just to set the current row onto this row */
975 GetRow(row_ptr->par, row_ptr->pos, unused_y);
977 /* ok , let us initialize the maxasc and maxdesc value.
978 * This depends in LaTeX of the font of the last character
979 * in the paragraph. The hack below is necessary because
980 * of the possibility of open footnotes */
982 /* Correction: only the fontsize count. The other properties
983 are taken from the layoutfont. Nicer on the screen :) */
985 LyXParagraph * par = row_ptr->par->LastPhysicalPar();
986 LyXParagraph * firstpar = row_ptr->par->FirstPhysicalPar();
988 LyXLayout const & layout = textclasslist.Style(parameters->textclass, firstpar->GetLayout());
990 LyXFont font = GetFont(par, par->Last()-1);
991 LyXFont::FONT_SIZE size = font.size();
992 font = GetFont(par, -1);
995 LyXFont labelfont = GetFont(par, -2);
997 maxasc = int(font.maxAscent() *
998 layout.spacing.getValue() *
999 parameters->spacing.getValue());
1000 maxdesc = int(font.maxDescent() *
1001 layout.spacing.getValue() *
1002 parameters->spacing.getValue());
1004 pos_end = RowLast(row_ptr);
1008 // Check if any insets are larger
1009 for (pos = row_ptr->pos; pos <= pos_end; pos++) {
1010 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_INSET) {
1011 tmpfont = GetFont(row_ptr->par, pos);
1012 tmpinset = row_ptr->par->GetInset(pos);
1014 asc = tmpinset->Ascent(tmpfont);
1015 desc = tmpinset->Descent(tmpfont);
1024 // Check if any custom fonts are larger (Asger)
1025 // This is not completely correct, but we can live with the small,
1026 // cosmetic error for now.
1027 LyXFont::FONT_SIZE maxsize = row_ptr->par->HighestFontInRange(row_ptr->pos, pos_end);
1028 if (maxsize > font.size()) {
1029 font.setSize(maxsize);
1031 asc = font.maxAscent();
1032 desc = font.maxDescent();
1039 /* table stuff -- begin*/
1040 if (row_ptr->par->table){
1041 // stretch the rows a bit
1045 /* table stuff -- end*/
1047 // This is nicer with box insets:
1051 row_ptr->ascent_of_text = maxasc;
1053 /* is it a top line? */
1054 if (row_ptr->pos == 0
1055 && row_ptr->par == firstpar) {
1057 /* some parksips VERY EASY IMPLEMENTATION */
1058 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
1059 if (layout.isParagraph()
1060 && firstpar->GetDepth() == 0
1061 && firstpar->Previous())
1062 maxasc += parameters->getDefSkip().inPixels();
1063 else if (firstpar->Previous()
1064 && textclasslist.Style(parameters->textclass,
1065 firstpar->Previous()->GetLayout()).isParagraph()
1066 && firstpar->Previous()->GetDepth() == 0)
1067 // is it right to use defskip here too? (AS)
1068 maxasc += parameters->getDefSkip().inPixels();
1071 /* the paper margins */
1072 if (!row_ptr->par->previous)
1073 maxasc += LYX_PAPER_MARGIN;
1075 /* add the vertical spaces, that the user added */
1076 if (firstpar->added_space_top.kind() != VSpace::NONE)
1077 maxasc += int(firstpar->added_space_top.inPixels());
1079 /* do not forget the DTP-lines!
1080 * there height depends on the font of the nearest character */
1081 if (firstpar->line_top)
1082 maxasc += 2 * GetFont(firstpar, 0).ascent('x');
1084 /* and now the pagebreaks */
1085 if (firstpar->pagebreak_top)
1086 maxasc += 3 * DefaultHeight();
1088 /* this is special code for the chapter, since the label of this
1089 * layout is printed in an extra row */
1090 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1091 && parameters->secnumdepth>= 0) {
1092 labeladdon = int(labelfont.maxDescent() *
1093 layout.spacing.getValue() *
1094 parameters->spacing.getValue())
1095 + int(labelfont.maxAscent() *
1096 layout.spacing.getValue() *
1097 parameters->spacing.getValue());
1100 /* special code for the top label */
1101 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1102 || layout.labeltype == LABEL_BIBLIO
1103 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1104 && row_ptr->par->IsFirstInSequence()
1105 && !row_ptr->par->GetLabestring().empty()) {
1107 (labelfont.maxAscent() *
1108 layout.spacing.getValue() *
1109 parameters->spacing.getValue())
1110 +(labelfont.maxDescent() *
1111 layout.spacing.getValue() *
1112 parameters->spacing.getValue())
1113 + layout.topsep * DefaultHeight()
1114 + layout.labelbottomsep * DefaultHeight());
1117 /* and now the layout spaces, for example before and after a section,
1118 * or between the items of a itemize or enumerate environment */
1120 if (!firstpar->pagebreak_top) {
1121 LyXParagraph *prev = row_ptr->par->Previous();
1123 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth());
1124 if (prev && prev->GetLayout() == firstpar->GetLayout()
1125 && prev->GetDepth() == firstpar->GetDepth()
1126 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1128 layoutasc = (layout.itemsep * DefaultHeight());
1130 else if (row_ptr->previous) {
1131 tmptop = layout.topsep;
1133 if (row_ptr->previous->par->GetDepth() >= row_ptr->par->GetDepth())
1134 tmptop-= textclasslist.Style(parameters->textclass, row_ptr->previous->par->GetLayout()).bottomsep;
1137 layoutasc = (tmptop * DefaultHeight());
1139 else if (row_ptr->par->line_top){
1140 tmptop = layout.topsep;
1143 layoutasc = (tmptop * DefaultHeight());
1146 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth()-1);
1148 maxasc += int(textclasslist.Style(parameters->textclass,
1149 prev->GetLayout()).parsep * DefaultHeight());
1152 if (firstpar->Previous()
1153 && firstpar->Previous()->GetDepth() == 0
1154 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1157 else if (firstpar->Previous()){
1158 maxasc += int(layout.parsep * DefaultHeight());
1164 /* is it a bottom line? */
1165 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
1166 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
1168 /* the paper margins */
1170 maxdesc += LYX_PAPER_MARGIN;
1172 /* add the vertical spaces, that the user added */
1173 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1174 maxdesc += int(firstpar->added_space_bottom.inPixels());
1176 /* do not forget the DTP-lines!
1177 * there height depends on the font of the nearest character */
1178 if (firstpar->line_bottom)
1179 maxdesc += 2 * (GetFont(par, par->Last()-1).ascent('x'));
1181 /* and now the pagebreaks */
1182 if (firstpar->pagebreak_bottom)
1183 maxdesc += 3 * DefaultHeight();
1185 /* and now the layout spaces, for example before and after a section,
1186 * or between the items of a itemize or enumerate environment */
1187 if (!firstpar->pagebreak_bottom && row_ptr->par->Next()) {
1188 LyXParagraph *nextpar = row_ptr->par->Next();
1189 LyXParagraph *comparepar = row_ptr->par;
1193 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1194 usual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1195 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1196 if (comparepar->GetLayout()!= nextpar->GetLayout()
1197 || nextpar->GetLabelWidthString() !=
1198 comparepar->GetLabelWidthString())
1199 unusual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1201 if (unusual > usual)
1202 layoutdesc = unusual;
1206 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1208 if (comparepar->GetLayout()!= nextpar->GetLayout()
1209 || nextpar->GetLabelWidthString() !=
1210 comparepar->GetLabelWidthString())
1211 layoutdesc = int(textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1216 /* incalculate the layout spaces */
1217 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1218 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1220 /* table stuff -- begin*/
1221 if (row_ptr->par->table){
1222 maxasc += row_ptr->par->table->
1223 AdditionalHeight(NumberOfCell(row_ptr->par, row_ptr->pos));
1225 /* table stuff -- end*/
1227 /* calculate the new height of the text */
1228 height -= row_ptr->height;
1230 row_ptr->height= maxasc+maxdesc+labeladdon;
1231 row_ptr->baseline= maxasc+labeladdon;
1233 height += row_ptr->height;
1237 /* Appends the implicit specified paragraph behind the specified row,
1238 * start at the implicit given position */
1239 void LyXText::AppendParagraph(Row * row) const
1241 bool not_ready = true;
1243 // The last character position of a paragraph is an invariant so we can
1244 // safely get it here. (Asger)
1245 int lastposition = row->par->Last();
1248 // Get the next breakpoint
1249 int z = NextBreakPoint(row, paperwidth);
1253 // Insert the new row
1254 if (z < lastposition) {
1256 InsertRow(row, row->par, z);
1263 // Set the dimensions of the row
1264 tmprow->fill = Fill(tmprow, paperwidth);
1265 SetHeightOfRow(tmprow);
1267 } while (not_ready);
1271 void LyXText::BreakAgain(Row * row) const
1273 bool not_ready = true;
1276 /* get the next breakpoint */
1277 LyXParagraph::size_type z =
1278 NextBreakPoint(row, paperwidth);
1281 if (z < row->par->Last() ) {
1282 if (!row->next || (row->next && row->next->par != row->par)) {
1285 InsertRow(row, row->par, z);
1292 not_ready = false; // the rest will not change
1298 /* if there are some rows too much, delete them */
1299 /* only if you broke the whole paragraph! */
1300 Row * tmprow2 = row;
1301 while (tmprow2->next && tmprow2->next->par == row->par) {
1302 tmprow2 = tmprow2->next;
1304 while (tmprow2 != row) {
1305 tmprow2 = tmprow2->previous;
1306 RemoveRow(tmprow2->next);
1311 /* set the dimensions of the row */
1312 tmprow->fill = Fill(tmprow, paperwidth);
1313 SetHeightOfRow(tmprow);
1314 } while (not_ready);
1318 /* this is just a little changed version of break again */
1319 void LyXText::BreakAgainOneRow(Row * row)
1321 /* get the next breakpoint */
1322 LyXParagraph::size_type z = NextBreakPoint(row, paperwidth);
1325 if (z < row->par->Last() ) {
1326 if (!row->next || (row->next && row->next->par != row->par)) {
1327 /* insert a new row */
1329 InsertRow(row, row->par, z);
1341 /* if there are some rows too much, delete them */
1342 /* only if you broke the whole paragraph! */
1343 Row * tmprow2 = row;
1344 while (tmprow2->next && tmprow2->next->par == row->par) {
1345 tmprow2 = tmprow2->next;
1347 while (tmprow2 != row) {
1348 tmprow2 = tmprow2->previous;
1349 RemoveRow(tmprow2->next);
1353 /* set the dimensions of the row */
1354 tmprow->fill = Fill(tmprow, paperwidth);
1355 SetHeightOfRow(tmprow);
1359 void LyXText::BreakParagraph(char keep_layout)
1361 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
1362 cursor.par->GetLayout());
1364 /* table stuff -- begin */
1365 if (cursor.par->table) {
1366 // breaking of tables is only allowed at the beginning or the end */
1367 if (cursor.pos && cursor.pos < cursor.par->size() &&
1368 !cursor.par->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par, cursor.pos)))
1369 return; // no breaking of tables allowed
1371 /* table stuff -- end */
1373 // this is only allowed, if the current paragraph is not empty or caption
1374 if ((cursor.par->Last() <= 0 && !cursor.par->IsDummy())
1376 layout.labeltype!= LABEL_SENSITIVE)
1379 SetUndo(Undo::INSERT,
1380 cursor.par->ParFromPos(cursor.pos)->previous,
1381 cursor.par->ParFromPos(cursor.pos)->next);
1383 /* table stuff -- begin */
1384 if (cursor.par->table) {
1385 int cell = NumberOfCell(cursor.par, cursor.pos);
1386 if (cursor.par->table->ShouldBeVeryLastCell(cell))
1387 SetCursor(cursor.par, cursor.par->text.size());
1389 /* table stuff -- end */
1391 // please break always behind a space
1392 if (cursor.pos < cursor.par->Last()
1393 && cursor.par->IsLineSeparator(cursor.pos))
1396 // break the paragraph
1400 keep_layout = layout.isEnvironment();
1401 cursor.par->BreakParagraph(cursor.pos, keep_layout);
1403 /* table stuff -- begin */
1404 if (cursor.par->table){
1405 // the table should stay with the contents
1407 cursor.par->Next()->table = cursor.par->table;
1408 cursor.par->table = 0;
1411 /* table stuff -- end */
1413 // well this is the caption hack since one caption is really enough
1414 if (layout.labeltype == LABEL_SENSITIVE){
1416 cursor.par->SetLayout(0); // set to standard-layout
1418 cursor.par->Next()->SetLayout(0); // set to standard-layout
1421 /* if the cursor is at the beginning of a row without prior newline,
1423 * This touches only the screen-update. Otherwise we would may have
1424 * an empty row on the screen */
1425 if (cursor.pos && !cursor.row->par->IsNewline(cursor.row->pos -1) &&
1426 cursor.row->pos == cursor.pos) {
1430 status = LyXText::NEED_MORE_REFRESH;
1431 refresh_row = cursor.row;
1432 refresh_y = cursor.y - cursor.row->baseline;
1434 // Do not forget the special right address boxes
1435 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1436 while (refresh_row->previous &&
1437 refresh_row->previous->par == refresh_row->par) {
1438 refresh_row = refresh_row->previous;
1439 refresh_y -= refresh_row->height;
1442 RemoveParagraph(cursor.row);
1444 // set the dimensions of the cursor row
1445 cursor.row->fill = Fill(cursor.row, paperwidth);
1447 SetHeightOfRow(cursor.row);
1449 while (!cursor.par->Next()->table && cursor.par->Next()->Last()
1450 && cursor.par->Next()->IsNewline(0))
1451 cursor.par->Next()->Erase(0);
1453 InsertParagraph(cursor.par->Next(), cursor.row);
1455 UpdateCounters(cursor.row->previous);
1457 /* This check is necessary. Otherwise the new empty paragraph will
1458 * be deleted automatically. And it is more friendly for the user! */
1460 SetCursor(cursor.par->Next(), 0);
1462 SetCursor(cursor.par, 0);
1464 if (cursor.row->next)
1465 BreakAgain(cursor.row->next);
1471 void LyXText::OpenFootnote()
1473 LyXParagraph * endpar,* tmppar;
1476 LyXParagraph * par = cursor.par->ParFromPos(cursor.pos);
1478 /* if there is no footnote in this paragraph, just return. */
1480 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1483 /* ok, move the cursor right before the footnote */
1485 /* just a little faster than using CursorRight() */
1486 for (cursor.pos= 0; cursor.par->ParFromPos(cursor.pos)!= par; cursor.pos++);
1487 /* now the cursor is at the beginning of the physical par */
1488 SetCursor(cursor.par,
1489 cursor.pos + cursor.par->ParFromPos(cursor.pos)->text.size());
1491 /* the cursor must be exactly before the footnote */
1492 par = cursor.par->ParFromPos(cursor.pos);
1494 status = LyXText::NEED_MORE_REFRESH;
1495 refresh_row = cursor.row;
1496 refresh_y = cursor.y - cursor.row->baseline;
1498 tmppar = cursor.par;
1499 endpar = cursor.par->Next();
1502 tmppar->OpenFootnote(cursor.pos);
1503 RemoveParagraph(row);
1504 /* set the dimensions of the cursor row */
1505 row->fill = Fill(row, paperwidth);
1506 SetHeightOfRow(row);
1507 tmppar = tmppar->Next();
1509 while (tmppar != endpar) {
1511 InsertParagraph(tmppar, row);
1512 while (row->next && row->next->par == tmppar)
1514 tmppar = tmppar->Next();
1517 SetCursor(par->next, 0);
1518 sel_cursor = cursor;
1522 /* table stuff -- begin*/
1524 void LyXText::TableFeatures(int feature, string const & val) const
1526 if (!cursor.par->table)
1527 return; /* this should never happen */
1529 int actCell = NumberOfCell(cursor.par, cursor.pos);
1530 SetUndo(Undo::FINISH,
1531 cursor.par->ParFromPos(cursor.pos)->previous,
1532 cursor.par->ParFromPos(cursor.pos)->next);
1535 case LyXTable::SET_PWIDTH:
1536 cursor.par->table->SetPWidth(actCell, val);
1538 case LyXTable::SET_SPECIAL_COLUMN:
1539 case LyXTable::SET_SPECIAL_MULTI:
1540 cursor.par->table->SetAlignSpecial(actCell, val, feature);
1549 void LyXText::TableFeatures(int feature) const
1552 int setAlign = LYX_ALIGN_LEFT;
1556 if (!cursor.par->table)
1557 return; /* this should never happen */
1559 int actCell = NumberOfCell(cursor.par, cursor.pos);
1560 SetUndo(Undo::FINISH,
1561 cursor.par->ParFromPos(cursor.pos)->previous,
1562 cursor.par->ParFromPos(cursor.pos)->next);
1565 case LyXTable::ALIGN_LEFT:
1566 setAlign= LYX_ALIGN_LEFT;
1568 case LyXTable::ALIGN_RIGHT:
1569 setAlign= LYX_ALIGN_RIGHT;
1571 case LyXTable::ALIGN_CENTER:
1572 setAlign= LYX_ALIGN_CENTER;
1578 case LyXTable::APPEND_ROW: {
1579 LyXParagraph::size_type pos = cursor.pos;
1581 /* move to the next row */
1582 int cell_org = actCell;
1583 int cell = cell_org;
1585 // if there is a ContRow following this row I have to add
1586 // the row after the ContRow's
1587 if ((pos < cursor.par->Last()) &&
1588 cursor.par->table->RowHasContRow(cell_org)) {
1589 while((pos < cursor.par->Last()) &&
1590 !cursor.par->table->IsContRow(cell)) {
1591 while (pos < cursor.par->Last() &&
1592 !cursor.par->IsNewline(pos))
1594 if (pos < cursor.par->Last())
1598 while((pos < cursor.par->Last()) &&
1599 cursor.par->table->IsContRow(cell)) {
1600 while (pos < cursor.par->Last() &&
1601 !cursor.par->IsNewline(pos))
1603 if (pos < cursor.par->Last())
1608 if (pos < cursor.par->Last())
1611 while (pos < cursor.par->Last() &&
1612 (cell == cell_org || !cursor.par->table->IsFirstCell(cell))){
1613 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1615 if (pos < cursor.par->Last())
1620 /* insert the new cells */
1621 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1622 for (int i = 0; i < number; ++i)
1623 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1625 /* append the row into the table */
1626 cursor.par->table->AppendRow(cell_org);
1630 case LyXTable::APPEND_CONT_ROW: {
1631 LyXParagraph::size_type pos = cursor.pos;
1632 /* move to the next row */
1633 int cell_org = actCell;
1634 int cell = cell_org;
1636 // if there is already a controw but not for this cell
1637 // the AppendContRow sets only the right values but does
1638 // not actually add a row
1639 if (cursor.par->table->RowHasContRow(cell_org) &&
1640 (cursor.par->table->CellHasContRow(cell_org)<0)) {
1641 cursor.par->table->AppendContRow(cell_org);
1645 while (pos < cursor.par->Last() &&
1647 || !cursor.par->table->IsFirstCell(cell))){
1648 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1650 if (pos < cursor.par->Last())
1655 /* insert the new cells */
1656 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1658 for (i= 0; i<number; i++)
1659 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1661 /* append the row into the table */
1662 cursor.par->table->AppendContRow(cell_org);
1666 case LyXTable::APPEND_COLUMN: {
1667 LyXParagraph::size_type pos = 0;
1668 int cell_org = actCell;
1671 if (pos && (cursor.par->IsNewline(pos-1))){
1672 if (cursor.par->table->AppendCellAfterCell(cell_org, cell)){
1673 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1674 if (pos <= cursor.pos)
1681 } while (pos <= cursor.par->Last());
1682 /* remember that the very last cell doesn't end with a newline.
1683 This saves one byte memory per table ;-) */
1684 if (cursor.par->table->AppendCellAfterCell(cell_org, cell))
1685 cursor.par->InsertChar(cursor.par->Last(), LyXParagraph::META_NEWLINE);
1687 /* append the column into the table */
1688 cursor.par->table->AppendColumn(cell_org);
1693 case LyXTable::DELETE_ROW:
1694 if (current_view->the_locking_inset)
1695 current_view->unlockInset(current_view->the_locking_inset);
1696 RemoveTableRow(&cursor);
1700 case LyXTable::DELETE_COLUMN: {
1701 LyXParagraph::size_type pos = 0;
1702 int cell_org = actCell;
1704 if (current_view->the_locking_inset)
1705 current_view->unlockInset(current_view->the_locking_inset);
1707 if (!pos || (cursor.par->IsNewline(pos-1))){
1708 if (cursor.par->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
1710 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1711 cursor.par->Erase(pos);
1712 if (pos < cursor.par->Last())
1713 cursor.par->Erase(pos);
1715 cursor.par->Erase(pos - 1); // the missing newline at the end of a table
1716 --pos; // because of pos++ below
1721 } while (pos <= cursor.par->Last());
1723 /* delete the column from the table */
1724 cursor.par->table->DeleteColumn(cell_org);
1726 /* set the cursor to the beginning of the table, where else? */
1731 case LyXTable::TOGGLE_LINE_TOP:
1732 lineSet = !cursor.par->table->TopLine(actCell);
1734 cursor.par->table->SetTopLine(actCell, lineSet);
1736 LyXParagraph::size_type i;
1738 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
1739 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
1740 cursor.par->table->SetTopLine(n, lineSet);
1748 case LyXTable::TOGGLE_LINE_BOTTOM:
1749 lineSet = !cursor.par->table->BottomLine(actCell);
1751 cursor.par->table->SetBottomLine(actCell, lineSet);
1753 LyXParagraph::size_type i;
1755 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
1756 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
1757 cursor.par->table->SetBottomLine(n, lineSet);
1765 case LyXTable::TOGGLE_LINE_LEFT:
1766 lineSet = !cursor.par->table->LeftLine(actCell);
1768 cursor.par->table->SetLeftLine(actCell, lineSet);
1770 LyXParagraph::size_type i;
1772 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
1773 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1774 cursor.par->table->SetLeftLine(n, lineSet);
1782 case LyXTable::TOGGLE_LINE_RIGHT:
1783 lineSet = !cursor.par->table->RightLine(actCell);
1785 cursor.par->table->SetRightLine(actCell, lineSet);
1787 LyXParagraph::size_type i;
1789 for (i= sel_start_cursor.pos; i<= sel_end_cursor.pos; i++){
1790 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1791 cursor.par->table->SetRightLine(n, lineSet);
1799 case LyXTable::ALIGN_LEFT:
1800 case LyXTable::ALIGN_RIGHT:
1801 case LyXTable::ALIGN_CENTER:
1803 cursor.par->table->SetAlignment(actCell, setAlign);
1805 LyXParagraph::size_type i;
1807 for (i= sel_start_cursor.pos; i<= sel_end_cursor.pos; i++){
1808 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1809 cursor.par->table->SetAlignment(n, setAlign);
1817 case LyXTable::DELETE_TABLE:
1818 SetCursorIntern(cursor.par, 0);
1819 delete cursor.par->table;
1820 cursor.par->table = 0;
1821 // temporary: Should put table in simple_cut_buffer (with before and after
1822 // dummy-paragraph !!
1823 // not necessar anymore with UNDO :)
1824 for (LyXParagraph::size_type i =
1825 cursor.par->text.size() - 1; i >= 0; --i)
1826 cursor.par->Erase(i);
1830 case LyXTable::MULTICOLUMN: {
1832 // check wether we are completly in a multicol
1833 int multicol = cursor.par->table->IsMultiColumn(actCell);
1834 if (multicol && selection && sel_start_cursor.row == sel_end_cursor.row){
1835 multicol = NumberOfCell(sel_start_cursor.par, sel_start_cursor.pos)
1836 == NumberOfCell(sel_end_cursor.par, sel_end_cursor.pos);
1840 int newlines = cursor.par->table->UnsetMultiColumn(actCell);
1841 LyXParagraph::size_type pos = cursor.pos;
1842 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1844 for (;newlines;newlines--)
1845 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1850 // selection must be in one row (or no selection)
1852 cursor.par->table->SetMultiColumn(NumberOfCell(cursor.par,
1859 if (sel_start_cursor.row == sel_end_cursor.row){
1860 LyXParagraph::size_type i;
1862 for (i = sel_start_cursor.pos;
1863 i < sel_end_cursor.pos; ++i){
1864 if (sel_start_cursor.par->IsNewline(i)){
1865 sel_start_cursor.par->Erase(i);
1866 // check for double-blanks
1867 if ((i && !sel_start_cursor.par->IsLineSeparator(i-1))
1869 (i < sel_start_cursor.par->Last()
1870 && !sel_start_cursor.par->IsLineSeparator(i)))
1871 sel_start_cursor.par->InsertChar(i, ' ');
1873 sel_end_cursor.pos--;
1880 SetMultiColumn(NumberOfCell(sel_start_cursor.par,
1881 sel_start_cursor.pos),
1883 cursor.pos = sel_start_cursor.pos;
1888 WriteAlert(_("Impossible Operation!"),
1889 _("Multicolumns can only be horizontally."),
1896 case LyXTable::SET_ALL_LINES:
1898 case LyXTable::UNSET_ALL_LINES:
1900 cursor.par->table->SetAllLines(NumberOfCell(cursor.par,
1904 LyXParagraph::size_type i;
1906 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
1907 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1908 cursor.par->table->SetAllLines(n, setLines);
1915 case LyXTable::SET_LONGTABLE:
1916 cursor.par->table->SetLongTable(true);
1918 case LyXTable::UNSET_LONGTABLE:
1919 cursor.par->table->SetLongTable(false);
1921 case LyXTable::SET_ROTATE_TABLE:
1922 cursor.par->table->SetRotateTable(true);
1924 case LyXTable::UNSET_ROTATE_TABLE:
1925 cursor.par->table->SetRotateTable(false);
1927 case LyXTable::SET_ROTATE_CELL:
1929 cursor.par->table->SetRotateCell(actCell, true);
1931 LyXParagraph::size_type i;
1933 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
1934 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
1935 cursor.par->table->SetRotateCell(n, true);
1941 case LyXTable::UNSET_ROTATE_CELL:
1943 cursor.par->table->SetRotateCell(actCell, false);
1945 LyXParagraph::size_type i;
1947 for (i= sel_start_cursor.pos; i<= sel_end_cursor.pos; i++){
1948 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1949 cursor.par->table->SetRotateCell(n, false);
1955 case LyXTable::SET_LINEBREAKS:
1956 what = !cursor.par->table->Linebreaks(cursor.par->table->FirstVirtualCell(actCell));
1958 cursor.par->table->SetLinebreaks(actCell, what);
1960 LyXParagraph::size_type i;
1962 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
1963 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
1964 cursor.par->table->SetLinebreaks(n, what);
1970 case LyXTable::SET_LTFIRSTHEAD:
1971 cursor.par->table->SetLTHead(actCell, true);
1973 case LyXTable::SET_LTHEAD:
1974 cursor.par->table->SetLTHead(actCell, false);
1976 case LyXTable::SET_LTFOOT:
1977 cursor.par->table->SetLTFoot(actCell, false);
1979 case LyXTable::SET_LTLASTFOOT:
1980 cursor.par->table->SetLTFoot(actCell, true);
1982 case LyXTable::SET_LTNEWPAGE:
1983 what = !cursor.par->table->LTNewPage(actCell);
1984 cursor.par->table->SetLTNewPage(actCell, what);
1990 void LyXText::InsertCharInTable(char c)
1995 bool jumped_over_space;
1997 /* first check, if there will be two blanks together or a blank at
1998 * the beginning of a paragraph.
1999 * I decided to handle blanks like normal characters, the main
2000 * difference are the special checks when calculating the row.fill
2001 * (blank does not count at the end of a row) and the check here */
2003 LyXFont realtmpfont = real_current_font;
2004 LyXFont rawtmpfont = current_font; /* store the current font.
2005 * This is because of the use
2006 * of cursor movements. The moving
2007 * cursor would refresh the
2010 // Get the font that is used to calculate the baselineskip
2011 LyXParagraph::size_type const lastpos =
2013 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2015 jumped_over_space = false;
2016 if (IsLineSeparatorChar(c)) {
2018 /* avoid double blanks but insert the new blank because
2019 * of a possible font change */
2020 if (cursor.pos < lastpos &&
2021 cursor.par->IsLineSeparator(cursor.pos))
2023 cursor.par->Erase(cursor.pos);
2024 jumped_over_space = true;
2026 else if ((cursor.pos > 0 &&
2027 cursor.par->IsLineSeparator(cursor.pos - 1))
2028 || (cursor.pos > 0 && cursor.par->IsNewline(cursor.pos - 1))
2029 || (cursor.pos == 0 &&
2030 !(cursor.par->Previous()
2031 && cursor.par->Previous()->footnoteflag
2032 == LyXParagraph::OPEN_FOOTNOTE)))
2035 else if (IsNewlineChar(c)) {
2036 if (!IsEmptyTableCell()) {
2037 TableFeatures(LyXTable::APPEND_CONT_ROW);
2044 y = cursor.y - row->baseline;
2045 if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset
2046 * already inserted the character */
2047 cursor.par->InsertChar(cursor.pos, c);
2048 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2050 if (!jumped_over_space) {
2051 /* refresh the positions */
2053 while (tmprow->next && tmprow->next->par == row->par) {
2054 tmprow = tmprow->next;
2061 CheckParagraphInTable(cursor.par, cursor.pos);
2063 current_font = rawtmpfont;
2064 real_current_font = realtmpfont;
2066 /* check, whether the last character's font has changed. */
2067 if (cursor.pos && cursor.pos == cursor.par->Last()
2068 && rawparfont != rawtmpfont)
2069 RedoHeightOfParagraph(cursor);
2073 void LyXText::CheckParagraphInTable(LyXParagraph * par,
2074 LyXParagraph::size_type pos)
2077 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
2078 par->GetInset(pos) && par->GetInset(pos)->display()){
2079 par->GetInset(pos)->display(false);
2083 Row * row = GetRow(par, pos, y);
2085 int tmpheight = row->height;
2086 SetHeightOfRow(row);
2088 LyXParagraph::size_type tmp_pos = pos;
2089 /* update the table information */
2090 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2092 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2093 WidthOfCell(par, tmp_pos))) {
2094 LyXCursor tmpcursor = cursor;
2095 SetCursorIntern(par, pos);
2096 /* make a complete redraw */
2097 RedoDrawingOfParagraph(cursor);
2101 /* redraw only the row */
2102 LyXCursor tmpcursor = cursor;
2103 SetCursorIntern(par, pos);
2105 refresh_x = cursor.x;
2107 refresh_pos = cursor.pos;
2110 if (tmpheight == row->height)
2111 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2113 status = LyXText::NEED_MORE_REFRESH;
2115 SetCursorIntern(cursor.par, cursor.pos);
2119 void LyXText::BackspaceInTable()
2121 Row * tmprow, * row;
2124 LyXFont rawtmpfont = current_font;
2125 LyXFont realtmpfont = real_current_font;
2127 // Get the font that is used to calculate the baselineskip
2128 int const lastpos = cursor.par->Last();
2129 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2131 if (cursor.pos == 0) {
2132 /* no pasting of table paragraphs */
2137 /* this is the code for a normal backspace, not pasting
2139 SetUndo(Undo::DELETE,
2140 cursor.par->ParFromPos(cursor.pos)->previous,
2141 cursor.par->ParFromPos(cursor.pos)->next);
2145 /* some insets are undeletable here */
2146 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
2147 if (!cursor.par->GetInset(cursor.pos)->Deletable())
2152 y = cursor.y - row->baseline;
2154 /* some special code when deleting a newline. */
2155 if (cursor.par->IsNewline(cursor.pos)) {
2160 cursor.par->Erase(cursor.pos);
2162 /* refresh the positions */
2164 while (tmprow->next && tmprow->next->par == row->par) {
2165 tmprow = tmprow->next;
2169 /* delete superfluous blanks */
2170 if (cursor.pos < cursor.par->Last() - 1 &&
2171 (cursor.par->IsLineSeparator(cursor.pos))) {
2173 if (cursor.pos == BeginningOfMainBody(cursor.par)
2175 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
2176 cursor.par->Erase(cursor.pos);
2177 /* refresh the positions */
2179 while (tmprow->next &&
2180 tmprow->next->par == row->par) {
2181 tmprow = tmprow->next;
2184 if (cursor.pos) /* move one character left */
2190 CheckParagraphInTable(cursor.par, cursor.pos);
2192 /* check, wether the last characters font has changed. */
2193 if (cursor.pos && cursor.pos == cursor.par->Last()
2194 && rawparfont != rawtmpfont)
2195 RedoHeightOfParagraph(cursor);
2197 /* restore the current font
2198 * That is what a user expects! */
2199 current_font = rawtmpfont;
2200 real_current_font = realtmpfont;
2202 SetCursorIntern(cursor.par, cursor.pos);
2205 /* table stuff -- end*/
2208 /* just a macro to make some thing easier. */
2209 void LyXText::RedoParagraph() const
2212 // I suspect this version will work
2215 RedoParagraphs(cursor, cursor.par->Next());
2216 SetCursorIntern(cursor.par, cursor.pos);
2218 LyXCursor tmpcursor = cursor;
2220 RedoParagraphs(cursor, cursor.par->Next());
2221 SetCursorIntern(tmpcursor.par, tmpcursor.pos);
2226 /* insert a character, moves all the following breaks in the
2227 * same Paragraph one to the right and make a rebreak */
2228 void LyXText::InsertChar(char c)
2230 SetUndo(Undo::INSERT,
2231 cursor.par->ParFromPos(cursor.pos)->previous,
2232 cursor.par->ParFromPos(cursor.pos)->next);
2234 /* When the free-spacing option is set for the current layout,
2235 * all spaces are converted to protected spaces. */
2236 bool freeSpacingBo =
2237 textclasslist.Style(parameters->textclass,
2238 cursor.row->par->GetLayout()).free_spacing;
2240 if (freeSpacingBo && IsLineSeparatorChar(c)
2241 && (!cursor.pos || cursor.par->IsLineSeparator(cursor.pos - 1)))
2242 c = LyXParagraph::META_PROTECTED_SEPARATOR;
2244 /* table stuff -- begin*/
2245 if (cursor.par->table) {
2246 InsertCharInTable(c);
2250 /* table stuff -- end*/
2252 /* First check, if there will be two blanks together or a blank at
2253 the beginning of a paragraph.
2254 I decided to handle blanks like normal characters, the main
2255 difference are the special checks when calculating the row.fill
2256 (blank does not count at the end of a row) and the check here */
2258 // The bug is triggered when we type in a description environment:
2259 // The current_font is not changed when we go from label to main text
2260 // and it should (along with realtmpfont) when we type the space.
2261 #ifdef WITH_WARNINGS
2262 #warning There is a bug here! (Asger)
2265 LyXFont realtmpfont = real_current_font;
2266 LyXFont rawtmpfont = current_font; /* store the current font.
2267 * This is because of the use
2268 * of cursor movements. The moving
2269 * cursor would refresh the
2272 // Get the font that is used to calculate the baselineskip
2273 LyXParagraph::size_type lastpos = cursor.par->Last();
2274 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2276 bool jumped_over_space = false;
2278 if (IsLineSeparatorChar(c)) {
2279 #ifndef FIX_DOUBLE_SPACE
2280 if (cursor.pos < lastpos
2281 && cursor.par->IsLineSeparator(cursor.pos)) {
2282 /* the user inserted a space before a space. So we
2283 * will just make a CursorRight. BUT: The font of this
2284 * space should be set to current font. That is why
2285 * we need to rebreak perhaps. If there is a protected
2286 * blank at the end of a row we have to force
2289 current_view->owner()->getMiniBuffer()
2290 ->Set(_("You cannot type two spaces this way. "
2291 " Please read the Tutorial."));
2293 // How can this ever happen?
2294 if (cursor.pos == RowLast(cursor.row)
2295 && !IsLineSeparatorChar(c))
2296 cursor.row->fill = -1; // force rebreak
2297 cursor.par->Erase(cursor.pos);
2298 jumped_over_space = true;
2300 // Seems to me that this works just as well.
2308 && cursor.par->IsLineSeparator(cursor.pos - 1))
2310 && cursor.par->IsNewline(cursor.pos - 1))
2312 && !(cursor.par->Previous()
2313 && cursor.par->Previous()->footnoteflag
2314 == LyXParagraph::OPEN_FOOTNOTE))) {
2315 if (cursor.pos == 0 )
2316 current_view->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2318 current_view->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2322 } else if (IsNewlineChar(c)) {
2323 if (cursor.par->FirstPhysicalPar() == cursor.par
2324 && cursor.pos <= BeginningOfMainBody(cursor.par)) {
2328 /* No newline at first position
2329 * of a paragraph or behind labels.
2330 * TeX does not allow that. */
2332 if (cursor.pos < cursor.par->Last() &&
2333 cursor.par->IsLineSeparator(cursor.pos))
2334 CursorRightIntern(); // newline always after a blank!
2335 cursor.row->fill = -1; // to force a new break
2338 // the display inset stuff
2339 if (cursor.row->par->GetChar(cursor.row->pos) == LyXParagraph::META_INSET
2340 && cursor.row->par->GetInset(cursor.row->pos)
2341 && cursor.row->par->GetInset(cursor.row->pos)->display())
2342 cursor.row->fill = -1; // to force a new break
2344 // get the cursor row fist
2345 Row * row = cursor.row;
2346 long y = cursor.y - row->baseline;
2347 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2348 * already insertet the character */
2349 cursor.par->InsertChar(cursor.pos, c);
2350 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2352 if (!jumped_over_space) {
2353 // refresh the positions
2355 while (tmprow->next && tmprow->next->par == row->par) {
2356 tmprow = tmprow->next;
2361 // Is there a break one row above
2362 if ((cursor.par->IsLineSeparator(cursor.pos)
2363 || cursor.par->IsNewline(cursor.pos)
2364 || cursor.row->fill == -1)
2365 && row->previous && row->previous->par == row->par) {
2366 LyXParagraph::size_type z = NextBreakPoint(row->previous,
2368 if ( z >= row->pos) {
2371 // set the dimensions of the row above
2372 row->previous->fill = Fill(row->previous, paperwidth);
2374 SetHeightOfRow(row->previous);
2376 y -= row->previous->height;
2378 refresh_row = row->previous;
2379 status = LyXText::NEED_MORE_REFRESH;
2381 BreakAgainOneRow(row);
2382 SetCursor(cursor.par, cursor.pos + 1);
2383 /* cursor MUST be in row now */
2385 if (row->next && row->next->par == row->par)
2386 need_break_row = row->next;
2390 current_font = rawtmpfont;
2391 real_current_font = realtmpfont;
2393 // check, wether the last characters font has changed.
2394 if (cursor.pos && cursor.pos == cursor.par->Last()
2395 && rawparfont != rawtmpfont)
2396 RedoHeightOfParagraph(cursor);
2403 /* recalculate the fill of the row */
2404 if (row->fill >= 0) /* needed because a newline
2405 * will set fill to -1. Otherwise
2406 * we would not get a rebreak! */
2407 row->fill = Fill(row, paperwidth);
2408 if (row->fill < 0 ) {
2411 refresh_x = cursor.x;
2412 refresh_pos = cursor.pos;
2413 status = LyXText::NEED_MORE_REFRESH;
2414 BreakAgainOneRow(row);
2415 /* will the cursor be in another row now? */
2416 if (RowLast(row) <= cursor.pos + 1 && row->next) {
2417 if (row->next && row->next->par == row->par)
2421 BreakAgainOneRow(row);
2423 SetCursor(cursor.par, cursor.pos + 1);
2424 if (row->next && row->next->par == row->par)
2425 need_break_row = row->next;
2429 current_font = rawtmpfont;
2430 real_current_font = realtmpfont;
2433 refresh_x = cursor.x;
2435 refresh_pos = cursor.pos;
2437 int tmpheight = row->height;
2438 SetHeightOfRow(row);
2439 if (tmpheight == row->height)
2440 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2442 status = LyXText::NEED_MORE_REFRESH;
2444 SetCursor(cursor.par, cursor.pos + 1);
2445 current_font = rawtmpfont;
2446 real_current_font = realtmpfont;
2449 /* check, wether the last characters font has changed. */
2450 if (cursor.pos && cursor.pos == cursor.par->Last()
2451 && rawparfont != rawtmpfont) {
2452 RedoHeightOfParagraph(cursor);
2454 /* now the special right address boxes */
2455 if (textclasslist.Style(parameters->textclass,
2456 cursor.par->GetLayout()).margintype
2457 == MARGIN_RIGHT_ADDRESS_BOX) {
2458 RedoDrawingOfParagraph(cursor);
2466 void LyXText::charInserted()
2468 // Here we could call FinishUndo for every 20 characters inserted.
2469 // This is from my experience how emacs does it.
2470 static unsigned int counter = 0;
2480 void LyXText::PrepareToPrint(Row * row, float & x,
2481 float & fill_separator,
2483 float & fill_label_hfill) const
2487 float w = row->fill;
2489 fill_label_hfill = 0;
2491 fill_label_hfill = 0;
2493 x = LeftMargin(row);
2495 /* is there a manual margin with a manual label */
2496 if (textclasslist.Style(parameters->textclass,
2497 row->par->GetLayout()).margintype == MARGIN_MANUAL
2498 && textclasslist.Style(parameters->textclass,
2499 row->par->GetLayout()).labeltype == LABEL_MANUAL) {
2501 nlh = NumberOfLabelHfills(row) + 1; /* one more since labels
2502 * are left aligned*/
2503 if (nlh && !row->par->GetLabelWidthString().empty()) {
2504 fill_label_hfill = LabelFill(row) / nlh;
2508 /* are there any hfills in the row? */
2509 nh = NumberOfHfills(row);
2511 /* table stuff -- begin*/
2512 if (row->par->table) {
2513 w = paperwidth - row->par->table->WidthOfTable()
2514 - x - RightMargin(row);
2515 nh = 0; /* ignore hfills in tables */
2517 /* table stuff -- end*/
2522 /* is it block, flushleft or flushright?
2523 * set x how you need it */
2525 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2526 align = textclasslist.Style(parameters->textclass, row->par->GetLayout()).align;
2528 align = row->par->FirstPhysicalPar()->align;
2530 /* center displayed insets */
2531 if (row->par->GetChar(row->pos) == LyXParagraph::META_INSET
2532 && row->par->GetInset(row->pos)
2533 && row->par->GetInset(row->pos)->display())
2534 align = LYX_ALIGN_CENTER;
2537 case LYX_ALIGN_BLOCK:
2538 ns = NumberOfSeparators(row);
2539 if (ns && row->next && row->next->par == row->par &&
2540 !(row->next->par->IsNewline(row->next->pos-1))
2541 && !(row->next->par->GetChar(row->next->pos) == LyXParagraph::META_INSET
2542 && row->next->par->GetInset(row->next->pos)
2543 && row->next->par->GetInset(row->next->pos)->display())
2545 fill_separator = w / ns;
2547 case LYX_ALIGN_RIGHT:
2550 case LYX_ALIGN_CENTER:
2558 /* important for the screen */
2561 /* the cursor set functions have a special mechanism. When they
2562 * realize, that you left an empty paragraph, they will delete it.
2563 * They also delete the corresponding row */
2565 void LyXText::CursorRightOneWord() const
2567 // treat floats, HFills and Insets as words
2568 LyXCursor tmpcursor = cursor;
2570 if (tmpcursor.pos == tmpcursor.par->Last()
2571 && tmpcursor.par->Next())
2573 tmpcursor.par = tmpcursor.par->Next();
2578 // Skip through initial nonword stuff.
2579 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2580 ! tmpcursor.par->IsWord( tmpcursor.pos ) )
2582 // printf("Current pos1 %d", tmpcursor.pos) ;
2586 // Advance through word.
2587 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2588 tmpcursor.par->IsWord( tmpcursor.pos ) )
2590 // printf("Current pos2 %d", tmpcursor.pos) ;
2595 SetCursor(tmpcursor.par, tmpcursor.pos);
2599 void LyXText::CursorTab() const
2601 if (cursor.par->table) {
2602 int cell = NumberOfCell(cursor.par, cursor.pos);
2603 while(cursor.par->table->IsContRow(cell)) {
2605 cell = NumberOfCell(cursor.par, cursor.pos);
2607 if (cursor.par->table->ShouldBeVeryLastCell(cell))
2608 TableFeatures(LyXTable::APPEND_ROW);
2610 LyXCursor tmpcursor = cursor;
2611 while (tmpcursor.pos < tmpcursor.par->Last()
2612 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2615 if (tmpcursor.pos == tmpcursor.par->Last()){
2616 if (tmpcursor.par->Next()) {
2617 tmpcursor.par = tmpcursor.par->Next();
2623 SetCursor(tmpcursor.par, tmpcursor.pos);
2624 if (cursor.par->table) {
2625 int cell = NumberOfCell(cursor.par, cursor.pos);
2626 while (cursor.par->table->IsContRow(cell) &&
2627 !cursor.par->table->ShouldBeVeryLastCell(cell)) {
2629 while (tmpcursor.pos < tmpcursor.par->Last()
2630 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2633 if (tmpcursor.pos == tmpcursor.par->Last()){
2634 if (tmpcursor.par->Next()) {
2635 tmpcursor.par = tmpcursor.par->Next();
2641 SetCursor(tmpcursor.par, tmpcursor.pos);
2642 cell = NumberOfCell(cursor.par, cursor.pos);
2648 /* -------> Skip initial whitespace at end of word and move cursor to *start*
2649 of prior word, not to end of next prior word. */
2651 void LyXText::CursorLeftOneWord() const
2653 // treat HFills, floats and Insets as words
2654 LyXCursor tmpcursor = cursor;
2655 while (tmpcursor.pos
2656 && (tmpcursor.par->IsSeparator(tmpcursor.pos - 1)
2657 || tmpcursor.par->IsKomma(tmpcursor.pos - 1))
2658 && !(tmpcursor.par->IsHfill(tmpcursor.pos - 1)
2659 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2660 || tmpcursor.par->IsInset(tmpcursor.pos - 1)))
2664 && (tmpcursor.par->IsInset(tmpcursor.pos - 1)
2665 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2666 || tmpcursor.par->IsHfill(tmpcursor.pos - 1))) {
2668 } else if (!tmpcursor.pos) {
2669 if (tmpcursor.par->Previous()){
2670 tmpcursor.par = tmpcursor.par->Previous();
2671 tmpcursor.pos = tmpcursor.par->Last();
2673 } else { // Here, tmpcursor != 0
2674 while (tmpcursor.pos > 0 &&
2675 tmpcursor.par->IsWord(tmpcursor.pos-1) )
2678 SetCursor(tmpcursor.par, tmpcursor.pos);
2681 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
2684 void LyXText::SelectWord()
2686 /* Move cursor to the beginning, when not already there. */
2688 && !cursor.par->IsSeparator(cursor.pos-1)
2689 && !cursor.par->IsKomma(cursor.pos-1) )
2690 CursorLeftOneWord();
2692 /* set the sel cursor */
2693 sel_cursor = cursor;
2695 while ( cursor.pos < cursor.par->Last()
2696 && !cursor.par->IsSeparator(cursor.pos)
2697 && !cursor.par->IsKomma(cursor.pos) )
2699 SetCursor( cursor.par, cursor.pos );
2701 /* finally set the selection */
2706 /* -------> Select the word currently under the cursor when:
2707 1: no selection is currently set,
2708 2: the cursor is not at the borders of the word. */
2710 int LyXText::SelectWordWhenUnderCursor()
2712 if ( selection ) return 0;
2713 if ( cursor.pos < cursor.par->Last()
2714 && !cursor.par->IsSeparator(cursor.pos)
2715 && !cursor.par->IsKomma(cursor.pos)
2717 && !cursor.par->IsSeparator(cursor.pos -1)
2718 && !cursor.par->IsKomma(cursor.pos -1) ) {
2726 // This function is only used by the spellchecker for NextWord().
2727 // It doesn't handle LYX_ACCENTs and probably never will.
2728 char * LyXText::SelectNextWord(float & value)
2730 LyXParagraph * tmppar = cursor.par;
2732 // If this is not the very first word, skip rest of
2733 // current word because we are probably in the middle
2734 // of a word if there is text here.
2735 if (cursor.pos || cursor.par->previous) {
2736 while (cursor.pos < cursor.par->Last()
2737 && cursor.par->IsLetter(cursor.pos))
2740 // Now, skip until we have real text (will jump paragraphs)
2741 while ((cursor.par->Last() > cursor.pos
2742 && (!cursor.par->IsLetter(cursor.pos)
2743 || cursor.par->getFont(cursor.pos).latex() == LyXFont::ON))
2744 || (cursor.par->Last() == cursor.pos
2745 && cursor.par->Next())){
2746 if (cursor.pos == cursor.par->Last()) {
2747 cursor.par = cursor.par->Next();
2754 // Update the value if we changed paragraphs
2755 if (cursor.par != tmppar){
2756 SetCursor(cursor.par, cursor.pos);
2757 value = float(cursor.y)/float(height);
2760 /* Start the selection from here */
2761 sel_cursor = cursor;
2765 /* and find the end of the word
2766 (optional hyphens are part of a word) */
2767 while (cursor.pos < cursor.par->Last()
2768 && (cursor.par->IsLetter(cursor.pos))
2769 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET &&
2770 cursor.par->GetInset(cursor.pos) != 0 &&
2771 cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 &&
2775 // Finally, we copy the word to a string and return it
2778 if (sel_cursor.pos < cursor.pos) {
2779 str = new char [cursor.pos - sel_cursor.pos + 2];
2780 LyXParagraph::size_type i, j;
2781 for (i = sel_cursor.pos, j = 0; i < cursor.pos; ++i) {
2782 if (cursor.par->GetChar(i) != LyXParagraph::META_INSET)
2783 str[j++] = cursor.par->GetChar(i);
2791 // This one is also only for the spellchecker
2792 void LyXText::SelectSelectedWord()
2794 /* move cursor to the beginning */
2795 SetCursor(sel_cursor.par, sel_cursor.pos);
2797 /* set the sel cursor */
2798 sel_cursor = cursor;
2802 /* now find the end of the word */
2803 while (cursor.pos < cursor.par->Last()
2804 && (cursor.par->IsLetter(cursor.pos)
2805 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET &&
2806 cursor.par->GetInset(cursor.pos) != 0 &&
2807 cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 &&
2811 SetCursor(cursor.par, cursor.pos);
2813 /* finally set the selection */
2818 /* -------> Delete from cursor up to the end of the current or next word. */
2819 void LyXText::DeleteWordForward()
2821 LyXCursor tmpcursor = cursor;
2823 if (!cursor.par->Last())
2826 /* -------> Skip initial non-word stuff. */
2827 while ( cursor.pos < cursor.par->Last()
2828 && (cursor.par->IsSeparator(cursor.pos)
2829 || cursor.par->IsKomma(cursor.pos)) )
2832 SetCursorIntern(cursor.par, cursor.pos);
2833 selection = True; // to avoid deletion
2834 CursorRightOneWord();
2835 sel_cursor = cursor;
2839 /* -----> Great, CutSelection() gets rid of multiple spaces. */
2845 /* -------> Delete from cursor to start of current or prior word. */
2846 void LyXText::DeleteWordBackward()
2848 LyXCursor tmpcursor = cursor;
2849 if (!cursor.par->Last())
2852 selection = true; // to avoid deletion
2853 CursorLeftOneWord();
2854 sel_cursor = cursor;
2862 /* -------> Kill to end of line. */
2863 void LyXText::DeleteLineForward()
2865 LyXCursor tmpcursor = cursor;
2866 if (!cursor.par->Last())
2870 sel_cursor = cursor;
2873 if (selection == false) {
2874 DeleteWordForward();
2882 // Change the case of a word at cursor position. The meaning of action
2884 // 0 change to lowercase
2885 // 1 capitalize word
2886 // 2 change to uppercase
2887 // This function directly manipulates LyXParagraph::text because there
2888 // is no LyXParagraph::SetChar currently. I did what I could to ensure
2889 // that it is correct. I guess part of it should be moved to
2890 // LyXParagraph, but it will have to change for 1.1 anyway. At least
2891 // it does not access outside of the allocated array as the older
2892 // version did. (JMarc)
2893 void LyXText::ChangeWordCase(LyXText::TextCase action)
2895 LyXParagraph * tmppar = cursor.par->ParFromPos(cursor.pos);
2897 SetUndo(Undo::FINISH, tmppar->previous, tmppar->next);
2899 LyXParagraph::size_type tmppos =
2900 cursor.par->PositionInParFromPos(cursor.pos);
2901 while (tmppos < tmppar->size()) {
2902 unsigned char c = tmppar->text[tmppos];
2903 if (IsKommaChar(c) || IsLineSeparatorChar(c))
2905 if (c != LyXParagraph::META_INSET) {
2907 case text_lowercase:
2910 case text_capitalization:
2912 action = text_lowercase;
2914 case text_uppercase:
2920 tmppar->text[tmppos] = c;
2923 CheckParagraph(tmppar, tmppos);
2924 CursorRightOneWord();
2928 void LyXText::Delete()
2930 // this is a very easy implementation
2932 LyXCursor old_cursor = cursor;
2933 int old_cur_par_id = old_cursor.par->id();
2934 int old_cur_par_prev_id = old_cursor.par->previous->id();
2936 // just move to the right
2937 CursorRightIntern();
2939 // This check is not very good...
2940 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
2941 // and that can very well delete the par or par->previous in
2942 // old_cursor. Will a solution where we compare paragraph id's
2945 if (cursor.par->previous->id() == old_cur_par_prev_id
2946 && cursor.par->id() != old_cur_par_id)
2947 return; // delete-empty-paragraph-mechanism has done it
2949 if (cursor.par->previous == old_cursor.par->previous
2950 && cursor.par != old_cursor.par)
2951 return; // delete-empty-paragraph-mechanism has done it
2953 // if you had success make a backspace
2954 if (old_cursor.par != cursor.par || old_cursor.pos != cursor.pos) {
2955 LyXCursor tmpcursor = cursor;
2956 cursor = old_cursor; // to make sure undo gets the right cursor position
2957 SetUndo(Undo::DELETE,
2958 cursor.par->ParFromPos(cursor.pos)->previous,
2959 cursor.par->ParFromPos(cursor.pos)->next);
2966 void LyXText::Backspace()
2968 LyXParagraph * tmppar;
2969 Row * tmprow, * row;
2973 /* table stuff -- begin */
2974 if (cursor.par->table) {
2978 /* table stuff -- end */
2980 LyXFont rawtmpfont = current_font;
2981 LyXFont realtmpfont = real_current_font;
2983 // Get the font that is used to calculate the baselineskip
2984 int const lastpos = cursor.par->Last();
2985 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2987 if (cursor.pos == 0) {
2988 // we may paste some paragraphs
2990 // is it an empty paragraph?
2993 || (lastpos == 1 && cursor.par->IsSeparator(0)))
2994 && !(cursor.par->Next()
2995 && cursor.par->footnoteflag ==
2996 LyXParagraph::NO_FOOTNOTE
2997 && cursor.par->Next()->footnoteflag ==
2998 LyXParagraph::OPEN_FOOTNOTE)) {
3000 if (cursor.par->previous) {
3001 tmppar = cursor.par->previous->FirstPhysicalPar();
3002 if (cursor.par->GetLayout() == tmppar->GetLayout()
3003 && cursor.par->footnoteflag == tmppar->footnoteflag
3004 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3006 tmppar->line_bottom = cursor.par->line_bottom;
3007 tmppar->added_space_bottom = cursor.par->added_space_bottom;
3008 tmppar->pagebreak_bottom = cursor.par->pagebreak_bottom;
3013 // the layout things can change the height of a row !
3014 tmpheight = cursor.row->height;
3015 SetHeightOfRow(cursor.row);
3016 if (cursor.row->height != tmpheight) {
3017 refresh_y = cursor.y - cursor.row->baseline;
3018 refresh_row = cursor.row;
3019 status = LyXText::NEED_MORE_REFRESH;
3024 if (cursor.par->ParFromPos(cursor.pos)->previous){
3025 SetUndo(Undo::DELETE,
3026 cursor.par->ParFromPos(cursor.pos)->previous->previous,
3027 cursor.par->ParFromPos(cursor.pos)->next);
3029 tmppar = cursor.par;
3030 tmprow = cursor.row;
3032 /* Pasting is not allowed, if the paragraphs have different
3033 layout. I think it is a real bug of all other
3034 word processors to allow it. It confuses the user.
3035 Even so with a footnote paragraph and a non-footnote
3036 paragraph. I will not allow pasting in this case,
3037 because the user would be confused if the footnote behaves
3038 different wether it is open or closed.
3040 Correction: Pasting is always allowed with standard-layout
3042 if (cursor.par != tmppar
3043 && (cursor.par->GetLayout() == tmppar->GetLayout()
3044 || !tmppar->GetLayout())
3045 && cursor.par->footnoteflag == tmppar->footnoteflag
3046 /* table stuff -- begin*/
3047 && !cursor.par->table /* no pasting of tables */
3048 /* table stuff -- end*/
3049 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3051 cursor.par->PasteParagraph();
3054 cursor.par->IsSeparator(cursor.pos - 1)))
3055 cursor.par->InsertChar(cursor.pos, ' ');
3060 status = LyXText::NEED_MORE_REFRESH;
3061 refresh_row = cursor.row;
3062 refresh_y = cursor.y - cursor.row->baseline;
3064 // remove the lost paragraph
3065 RemoveParagraph(tmprow);
3068 AppendParagraph(cursor.row);
3069 UpdateCounters(cursor.row);
3071 // the row may have changed, block, hfills etc.
3072 SetCursor(cursor.par, cursor.pos);
3075 /* this is the code for a normal backspace, not pasting
3077 SetUndo(Undo::DELETE,
3078 cursor.par->ParFromPos(cursor.pos)->previous,
3079 cursor.par->ParFromPos(cursor.pos)->next);
3082 // some insets are undeletable here
3083 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
3084 if (!cursor.par->GetInset(cursor.pos)->Deletable())
3086 // force complete redo when erasing display insets
3087 // this is a cruel mathod but save..... Matthias
3088 if (cursor.par->GetInset(cursor.pos)->display()){
3089 cursor.par->Erase(cursor.pos);
3096 y = cursor.y - row->baseline;
3097 LyXParagraph::size_type z;
3098 /* remember that a space at the end of a row doesnt count
3099 * when calculating the fill */
3100 if (cursor.pos < RowLast(row) ||
3101 !cursor.par->IsLineSeparator(cursor.pos)) {
3102 row->fill += SingleWidth(cursor.par, cursor.pos);
3105 /* some special code when deleting a newline. This is similar
3106 * to the behavior when pasting paragraphs */
3107 if (cursor.pos && cursor.par->IsNewline(cursor.pos)) {
3108 cursor.par->Erase(cursor.pos);
3109 // refresh the positions
3111 while (tmprow->next && tmprow->next->par == row->par) {
3112 tmprow = tmprow->next;
3115 if (cursor.par->IsLineSeparator(cursor.pos - 1))
3118 if (cursor.pos < cursor.par->Last() && !cursor.par->IsSeparator(cursor.pos)) {
3119 cursor.par->InsertChar(cursor.pos, ' ');
3120 // refresh the positions
3122 while (tmprow->next && tmprow->next->par == row->par) {
3123 tmprow = tmprow->next;
3128 cursor.par->Erase(cursor.pos);
3130 // refresh the positions
3132 while (tmprow->next && tmprow->next->par == row->par) {
3133 tmprow = tmprow->next;
3137 #ifndef FIX_DOUBLE_SPACE
3138 // delete superfluous blanks
3139 if (cursor.pos < cursor.par->Last() - 1 &&
3140 (cursor.par->IsLineSeparator(cursor.pos))) {
3142 if (cursor.pos == BeginningOfMainBody(cursor.par)
3144 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
3145 cursor.par->Erase(cursor.pos);
3146 // refresh the positions
3148 while (tmprow->next &&
3149 tmprow->next->par == row->par) {
3150 tmprow = tmprow->next;
3153 if (cursor.pos) // move one character left
3159 // delete newlines at the beginning of paragraphs
3160 while (cursor.par->Last() &&
3161 cursor.par->IsNewline(cursor.pos) &&
3162 cursor.pos == BeginningOfMainBody(cursor.par)) {
3163 cursor.par->Erase(cursor.pos);
3164 // refresh the positions
3166 while (tmprow->next &&
3167 tmprow->next->par == row->par) {
3168 tmprow = tmprow->next;
3174 // is there a break one row above
3175 if (row->previous && row->previous->par == row->par) {
3176 z = NextBreakPoint(row->previous, paperwidth);
3177 if ( z >= row->pos) {
3180 tmprow = row->previous;
3182 // maybe the current row is now empty
3183 if (row->pos >= row->par->Last()) {
3188 BreakAgainOneRow(row);
3189 if (row->next && row->next->par == row->par)
3190 need_break_row = row->next;
3195 // set the dimensions of the row above
3196 y -= tmprow->height;
3197 tmprow->fill = Fill(tmprow, paperwidth);
3198 SetHeightOfRow(tmprow);
3201 refresh_row = tmprow;
3202 status = LyXText::NEED_MORE_REFRESH;
3203 SetCursor(cursor.par, cursor.pos);
3204 current_font = rawtmpfont;
3205 real_current_font = realtmpfont;
3206 // check, whether the last character's font has changed.
3207 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3208 if (rawparfont != rawtmpfont)
3209 RedoHeightOfParagraph(cursor);
3214 // break the cursor row again
3215 z = NextBreakPoint(row, paperwidth);
3217 if (z != RowLast(row) ||
3218 (row->next && row->next->par == row->par &&
3219 RowLast(row) == row->par->Last() - 1)){
3221 /* it can happen that a paragraph loses one row
3222 * without a real breakup. This is when a word
3223 * is to long to be broken. Well, I don t care this
3225 if (row->next && row->next->par == row->par &&
3226 RowLast(row) == row->par->Last() - 1)
3227 RemoveRow(row->next);
3231 status = LyXText::NEED_MORE_REFRESH;
3233 BreakAgainOneRow(row);
3235 SetCursor(cursor.par, cursor.pos);
3236 // cursor MUST be in row now
3238 if (row->next && row->next->par == row->par)
3239 need_break_row = row->next;
3243 // set the dimensions of the row
3244 row->fill = Fill(row, paperwidth);
3245 int tmpheight = row->height;
3246 SetHeightOfRow(row);
3247 if (tmpheight == row->height)
3248 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3250 status = LyXText::NEED_MORE_REFRESH;
3253 SetCursor(cursor.par, cursor.pos);
3257 // restore the current font
3258 // That is what a user expects!
3259 current_font = rawtmpfont;
3260 real_current_font = realtmpfont;
3262 // check, wether the last characters font has changed.
3263 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3264 if (rawparfont != rawtmpfont) {
3265 RedoHeightOfParagraph(cursor);
3267 // now the special right address boxes
3268 if (textclasslist.Style(parameters->textclass,
3269 cursor.par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3270 RedoDrawingOfParagraph(cursor);
3276 void LyXText::GetVisibleRow(LyXScreen & scr, int offset,
3277 Row * row_ptr, long y)
3279 /* returns a printed row */
3280 LyXParagraph::size_type pos, pos_end;
3282 int y_top, y_bottom;
3283 float fill_separator, fill_hfill, fill_label_hfill;
3284 LyXParagraph * par, * firstpar;
3288 if (row_ptr->height <= 0) {
3289 lyxerr << "LYX_ERROR: row.height: " << row_ptr->height << endl;
3292 left_margin = LabelEnd(row_ptr);
3293 PrepareToPrint(row_ptr, x, fill_separator,
3294 fill_hfill, fill_label_hfill);
3296 LyXParagraph::size_type main_body =
3297 BeginningOfMainBody(row_ptr->par);
3298 /* initialize the pixmap */
3300 scr.fillRectangle(gc_clear,
3301 0, offset, paperwidth, row_ptr->height);
3302 // check for NOT FAST SELECTION
3303 if (!fast_selection && !mono_video && selection) {
3304 /* selection code */
3305 if (sel_start_cursor.row == row_ptr &&
3306 sel_end_cursor.row == row_ptr) {
3307 scr.fillRectangle(gc_selection, sel_start_cursor.x,
3313 else if (sel_start_cursor.row == row_ptr) {
3314 scr.fillRectangle(gc_selection, sel_start_cursor.x,
3316 paperwidth - sel_start_cursor.x,
3318 } else if (sel_end_cursor.row == row_ptr) {
3319 scr.fillRectangle(gc_selection, 0, offset,
3320 sel_end_cursor.x, row_ptr->height);
3321 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
3322 scr.fillRectangle(gc_selection, 0, offset,
3323 paperwidth, row_ptr->height);
3326 } // end of NOT FAST SELECTION code
3328 if (row_ptr->par->appendix){
3329 scr.drawVerticalLine(gc_math, 1, offset, offset+row_ptr->height);
3330 scr.drawVerticalLine(gc_math, paperwidth-2 , offset, offset+row_ptr->height);
3333 if (row_ptr->par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
3334 /* draw a marker at the left margin! */
3335 LyXFont font = GetFont(row_ptr->par, 0);
3336 int asc = font.maxAscent();
3337 int x = (LYX_PAPER_MARGIN - font.width('|')) / 2;
3338 int y1 = (offset + row_ptr->baseline);
3339 int y2 = (offset + row_ptr->baseline) - asc;
3341 scr.drawVerticalLine(gc_minipage, x, y1, y2);
3343 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3344 LyXFont font(LyXFont::ALL_SANE);
3345 font.setSize(LyXFont::SIZE_FOOTNOTE);
3346 font.setColor(LyXFont::RED);
3348 int box_x = LYX_PAPER_MARGIN;
3349 box_x += font.textWidth(" wide-tab ", 10);
3350 if (row_ptr->previous &&
3351 row_ptr->previous->par->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3353 switch (row_ptr->par->footnotekind) {
3354 case LyXParagraph::MARGIN:
3357 case LyXParagraph::FIG:
3360 case LyXParagraph::TAB:
3363 case LyXParagraph::WIDE_FIG:
3366 case LyXParagraph::WIDE_TAB:
3369 case LyXParagraph::ALGORITHM:
3372 case LyXParagraph::FOOTNOTE:
3377 // Determine background color.
3378 gc_type back = gc_lighted;
3382 scr.fillRectangle(back, LYX_PAPER_MARGIN, offset+1,
3383 box_x - LYX_PAPER_MARGIN,
3384 int(font.maxAscent())+
3385 int(font.maxDescent()));
3387 scr.drawLine(gc_foot,
3390 paperwidth - 2*LYX_PAPER_MARGIN);
3392 scr.drawString(font, fs,
3393 offset + int(font.maxAscent())+1,
3395 scr.drawVerticalLine(gc_foot,
3399 + int(font.maxAscent())+
3400 int(font.maxDescent()));
3402 scr.drawLine(gc_foot,
3404 + int(font.maxAscent())
3405 + int(font.maxDescent()) + 1,
3406 LYX_PAPER_MARGIN, box_x - LYX_PAPER_MARGIN);
3409 /* draw the open floats in a red box */
3410 scr.drawVerticalLine(gc_foot,
3412 offset, offset + row_ptr->height);
3414 scr.drawVerticalLine(gc_foot,
3415 paperwidth - LYX_PAPER_MARGIN,
3417 offset + row_ptr->height);
3421 if (row_ptr->previous &&
3422 row_ptr->previous->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3423 LyXFont font(LyXFont::ALL_SANE);
3424 font.setSize(LyXFont::SIZE_FOOTNOTE);
3426 int box_x = LYX_PAPER_MARGIN;
3427 box_x += font.textWidth(" wide-tab ", 10);
3429 scr.drawLine(gc_foot,
3432 paperwidth - LYX_PAPER_MARGIN - box_x);
3436 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
3437 row_ptr->par->GetLayout());
3438 firstpar = row_ptr->par->FirstPhysicalPar();
3441 y_bottom = row_ptr->height;
3443 /* is it a first row? */
3444 if (row_ptr->pos == 0
3445 && row_ptr->par == firstpar) {
3447 /* start of appendix? */
3448 if (row_ptr->par->start_of_appendix){
3449 scr.drawLine(gc_math,
3454 /* think about the margins */
3455 if (!row_ptr->previous)
3456 y_top += LYX_PAPER_MARGIN;
3458 if (row_ptr->par->pagebreak_top){ /* draw a top pagebreak */
3459 scr.drawOnOffLine(offset + y_top + 2 * DefaultHeight(),
3461 y_top += 3 * DefaultHeight();
3464 if (row_ptr->par->added_space_top.kind() == VSpace::VFILL) {
3465 /* draw a vfill top */
3466 scr.drawLine(gc_fill,
3468 0, LYX_PAPER_MARGIN);
3469 scr.drawLine(gc_fill,
3470 offset + y_top + 3 * DefaultHeight(),
3471 0, LYX_PAPER_MARGIN);
3472 scr.drawVerticalOnOffLine(LYX_PAPER_MARGIN / 2,
3474 offset + y_top + 3 *
3477 y_top += 3 * DefaultHeight();
3480 /* think about user added space */
3481 y_top += int(row_ptr->par->added_space_top.inPixels());
3483 /* think about the parskip */
3484 /* some parskips VERY EASY IMPLEMENTATION */
3485 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
3486 if (layout.latextype == LATEX_PARAGRAPH
3487 && firstpar->GetDepth() == 0
3488 && firstpar->Previous())
3489 y_top += parameters->getDefSkip().inPixels();
3490 else if (firstpar->Previous()
3491 && textclasslist.Style(parameters->textclass,
3492 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
3493 && firstpar->Previous()->GetDepth() == 0)
3494 // is it right to use defskip here, too? (AS)
3495 y_top += parameters->getDefSkip().inPixels();
3498 if (row_ptr->par->line_top) { /* draw a top line */
3499 y_top += GetFont(row_ptr->par, 0).ascent('x');
3501 scr.drawThickLine(offset + y_top,
3503 y_top += GetFont(row_ptr->par, 0).ascent('x');
3506 /* should we print a label? */
3507 if (layout.labeltype >= LABEL_STATIC
3508 && (layout.labeltype != LABEL_STATIC
3509 || layout.latextype != LATEX_ENVIRONMENT
3510 || row_ptr->par->IsFirstInSequence())) {
3511 font = GetFont(row_ptr->par, -2);
3512 if (!row_ptr->par->GetLabestring().empty()) {
3514 string tmpstring = row_ptr->par->GetLabestring();
3516 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
3517 if (parameters->secnumdepth >= 0){
3518 /* this is special code for the chapter layout. This is printed in
3519 * an extra row and has a pagebreak at the top. */
3520 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue())
3521 + int(layout.parsep) * DefaultHeight();
3522 scr.drawString(font, tmpstring,
3523 offset + row_ptr->baseline
3524 - row_ptr->ascent_of_text - maxdesc,
3528 x -= font.stringWidth( layout.labelsep);
3529 x -= font.stringWidth( tmpstring);
3531 scr.drawString(font, tmpstring,
3532 offset + row_ptr->baseline, int(x));
3536 /* the labels at the top of an environment. More or less for bibliography */
3537 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
3538 layout.labeltype == LABEL_BIBLIO ||
3539 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
3540 if (row_ptr->par->IsFirstInSequence()) {
3541 font = GetFont(row_ptr->par, -2);
3542 if (!row_ptr->par->GetLabestring().empty()) {
3543 string tmpstring = row_ptr->par->GetLabestring();
3545 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue()
3546 + (layout.labelbottomsep * DefaultHeight()));
3548 int top_label_x = int(x);
3549 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
3550 top_label_x = int(x + (paperwidth - RightMargin(row_ptr) - x) / 2);
3551 top_label_x -= (font.stringWidth( tmpstring)/2);
3554 scr.drawString(font, tmpstring,
3555 offset + row_ptr->baseline
3556 - row_ptr->ascent_of_text - maxdesc,
3561 if (layout.labeltype == LABEL_BIBLIO) { // ale970302
3562 if (row_ptr->par->bibkey) {
3564 x -= font.stringWidth(layout.labelsep);
3565 font = GetFont(row_ptr->par, -1);
3566 x -= row_ptr->par->bibkey->Width(font);
3567 row_ptr->par->bibkey->Draw(font, scr,
3568 offset + row_ptr->baseline,
3575 /* is it a last row? */
3576 par = row_ptr->par->LastPhysicalPar();
3577 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
3578 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
3580 /* think about the margins */
3582 y_bottom -= LYX_PAPER_MARGIN;
3584 /* draw a bottom pagebreak */
3585 if (firstpar->pagebreak_bottom) {
3586 scr.drawOnOffLine(offset + y_bottom - 2 *
3589 y_bottom -= 3 * DefaultHeight();
3592 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
3593 /* draw a vfill bottom */
3594 scr.drawLine(gc_fill,
3595 offset + y_bottom - 3 * DefaultHeight(),
3596 0, LYX_PAPER_MARGIN);
3597 scr.drawLine(gc_fill, offset + y_bottom - 2,
3598 0, LYX_PAPER_MARGIN);
3599 scr.drawVerticalOnOffLine(LYX_PAPER_MARGIN / 2,
3600 offset + y_bottom - 3 * DefaultHeight(),
3601 offset + y_bottom - 2
3603 y_bottom -= 3* DefaultHeight();
3606 /* think about user added space */
3607 y_bottom -= int(firstpar->added_space_bottom.inPixels());
3609 if (firstpar->line_bottom) {
3610 /* draw a bottom line */
3611 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3613 scr.drawThickLine(offset + y_bottom,
3615 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3619 /* draw the text in the pixmap */
3620 pos_end = RowLast(row_ptr);
3623 /* table stuff -- begin*/
3624 if (row_ptr->par->table) {
3626 int cell = NumberOfCell(row_ptr->par, row_ptr->pos);
3628 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3630 while (pos <= pos_end) {
3631 if (row_ptr->par->IsNewline(pos)) {
3633 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
3634 /* draw the table lines, still very simple */
3635 on_off = !row_ptr->par->table->TopLine(cell);
3637 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
3638 !row_ptr->par->table->IsContRow(cell))
3639 scr.drawTableLine(offset + row_ptr->baseline -
3640 row_ptr->ascent_of_text,
3641 int(x_old), int(x - x_old), on_off);
3642 on_off = !row_ptr->par->table->BottomLine(cell);
3643 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
3644 row_ptr->par->table->VeryLastRow(cell))
3645 scr.drawTableLine(offset + y_bottom - 1,
3646 int(x_old), int(x - x_old), on_off);
3647 on_off = !row_ptr->par->table->LeftLine(cell);
3649 scr.drawVerticalTableLine(int(x_old),
3650 offset + row_ptr->baseline -
3651 row_ptr->ascent_of_text,
3652 offset + y_bottom - 1,
3654 on_off = !row_ptr->par->table->RightLine(cell);
3656 scr.drawVerticalTableLine(int(x) -
3657 row_ptr->par->table->AdditionalWidth(cell),
3658 offset + row_ptr->baseline -
3659 row_ptr->ascent_of_text,
3660 offset + y_bottom - 1,
3663 /* take care about the alignment and other spaces */
3665 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3666 if (row_ptr->par->table->IsFirstCell(cell))
3667 cell--; // little hack, sorry
3669 } else if (row_ptr->par->IsHfill(pos)) {
3672 scr.drawVerticalLine(gc_fill, int(x),
3673 offset + row_ptr->baseline - DefaultHeight()/2,
3674 offset + row_ptr->baseline);
3678 if (row_ptr->par->IsSeparator(pos)) {
3680 x+= SingleWidth(row_ptr->par, pos);
3681 /* -------> Only draw protected spaces when not in
3682 * free-spacing mode. */
3683 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
3684 scr.drawVerticalLine(gc_fill, int(tmpx),
3685 offset + row_ptr->baseline - 3,
3686 offset + row_ptr->baseline - 1);
3687 scr.drawLine(gc_fill,
3688 offset + row_ptr->baseline - 1,
3691 scr.drawVerticalLine(gc_fill, int(x-2),
3692 offset + row_ptr->baseline - 3,
3693 offset + row_ptr->baseline - 1);
3694 /* what about underbars? */
3695 font = GetFont(row_ptr->par, pos);
3696 if (font.underbar() == LyXFont::ON
3697 && font.latex() != LyXFont::ON) {
3698 scr.drawLine(gc_copy,
3700 row_ptr->baseline + 2,
3707 Draw(row_ptr, pos, scr, offset, x);
3711 /* do not forget the very last cell. This has no NEWLINE so
3712 * ignored by the code above*/
3713 if (cell == row_ptr->par->table->GetNumberOfCells()-1){
3714 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
3715 on_off = !row_ptr->par->table->TopLine(cell);
3717 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
3718 !row_ptr->par->table->IsContRow(cell))
3720 scr.drawTableLine(offset + row_ptr->baseline -
3721 row_ptr->ascent_of_text,
3722 int(x_old), int(x - x_old), on_off);
3723 on_off = !row_ptr->par->table->BottomLine(cell);
3724 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
3725 row_ptr->par->table->VeryLastRow(cell))
3727 scr.drawTableLine(offset + y_bottom - 1,
3728 int(x_old), int(x - x_old), on_off);
3729 on_off = !row_ptr->par->table->LeftLine(cell);
3731 scr.drawVerticalTableLine(int(x_old),
3732 offset + row_ptr->baseline -
3733 row_ptr->ascent_of_text,
3734 offset + y_bottom - 1,
3736 on_off = !row_ptr->par->table->RightLine(cell);
3738 scr.drawVerticalTableLine(int(x) -
3739 row_ptr->par->table->AdditionalWidth(cell),
3740 offset + row_ptr->baseline -
3741 row_ptr->ascent_of_text,
3742 offset + y_bottom - 1,
3746 /* table stuff -- end*/
3748 while (pos <= pos_end) {
3750 if (row_ptr->par->IsHfill(pos)) {
3752 scr.drawVerticalLine(gc_fill, int(x),
3753 offset + row_ptr->baseline - DefaultHeight()/2,
3754 offset + row_ptr->baseline);
3755 if (HfillExpansion(row_ptr, pos)) {
3756 if (pos >= main_body) {
3757 scr.drawOnOffLine(offset + row_ptr->baseline -
3763 scr.drawOnOffLine(offset + row_ptr->baseline -
3766 int(fill_label_hfill));
3767 x += fill_label_hfill;
3769 scr.drawVerticalLine(gc_fill, int(x),
3770 offset + row_ptr->baseline -
3772 offset + row_ptr->baseline);
3777 if (row_ptr->par->IsSeparator(pos)) {
3779 x+= SingleWidth(row_ptr->par, pos);
3780 if (pos >= main_body)
3782 /* -------> Only draw protected spaces when not in
3783 * free-spacing mode. */
3784 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
3786 scr.drawVerticalLine(gc_fill, int(tmpx),
3787 offset + row_ptr->baseline - 3,
3788 offset + row_ptr->baseline - 1);
3789 scr.drawLine(gc_fill,
3790 offset + row_ptr->baseline - 1,
3793 scr.drawVerticalLine(gc_fill, int(x-2),
3794 offset + row_ptr->baseline - 3,
3795 offset + row_ptr->baseline - 1);
3796 /* what about underbars? */
3797 font = GetFont(row_ptr->par, pos);
3798 if (font.underbar() == LyXFont::ON
3799 && font.latex() != LyXFont::ON) {
3800 scr.drawLine(gc_copy,
3801 offset + row_ptr->baseline + 2,
3808 Draw(row_ptr, pos, scr, offset, x);
3810 if (pos == main_body) {
3811 x += GetFont(row_ptr->par, -2).stringWidth(
3813 if (row_ptr->par->IsLineSeparator(pos - 1))
3814 x-= SingleWidth(row_ptr->par, pos - 1);
3815 if (x < left_margin)
3820 // check for FAST SELECTION
3821 if (fast_selection || mono_video) {
3824 /* selection code */
3825 if (sel_start_cursor.row == row_ptr && sel_end_cursor.row == row_ptr) {
3826 scr.fillRectangle(gc_select, sel_start_cursor.x, offset,
3827 sel_end_cursor.x - sel_start_cursor.x,
3829 } else if (sel_start_cursor.row == row_ptr) {
3830 scr.fillRectangle(gc_select, sel_start_cursor.x, offset,
3831 paperwidth - sel_start_cursor.x,
3833 } else if (sel_end_cursor.row == row_ptr) {
3834 scr.fillRectangle(gc_select, 0, offset,
3837 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
3838 scr.fillRectangle(gc_select, 0, offset,
3839 paperwidth, row_ptr->height);
3844 // end of FAST SELECTION code
3849 int LyXText::DefaultHeight() const
3851 LyXFont font(LyXFont::ALL_SANE);
3852 return int(font.maxAscent() + font.maxDescent() * 1.5);
3856 /* returns the column near the specified x-coordinate of the row
3857 * x is set to the real beginning of this column */
3858 int LyXText::GetColumnNearX(Row * row, int & x) const
3861 float fill_separator, fill_hfill, fill_label_hfill;
3863 int left_margin = LabelEnd(row);
3864 PrepareToPrint(row, tmpx, fill_separator,
3865 fill_hfill, fill_label_hfill);
3866 int main_body = BeginningOfMainBody(row->par);
3870 int last = RowLast(row);
3871 if (row->par->IsNewline(last))
3874 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
3875 row->par->GetLayout());
3876 /* table stuff -- begin */
3877 if (row->par->table) {
3878 if (!row->next || row->next->par != row->par)
3879 last = RowLast(row); /* the last row doesn't need a newline at the end*/
3880 int cell = NumberOfCell(row->par, row->pos);
3883 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
3885 && tmpx + (SingleWidth(row->par, c)/2) <= x
3887 if (row->par->IsNewline(c)) {
3888 if (x_old + row->par->table->WidthOfColumn(cell) <= x){
3889 tmpx = x_old + row->par->table->WidthOfColumn(cell);
3892 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
3897 tmpx += SingleWidth(row->par, c);
3902 /* table stuff -- end*/
3905 && tmpx + (SingleWidth(row->par, c)/2) <= x) {
3907 if (c && c == main_body
3908 && !row->par->IsLineSeparator(c - 1)) {
3909 tmpx += GetFont(row->par, -2)
3910 .stringWidth(layout.labelsep);
3911 if (tmpx < left_margin)
3915 tmpx += SingleWidth(row->par, c);
3916 if (HfillExpansion(row, c)) {
3920 tmpx += fill_label_hfill;
3922 else if (c >= main_body
3923 && row->par->IsSeparator(c)) {
3924 tmpx+= fill_separator;
3928 && row->par->IsLineSeparator(c - 1)) {
3929 tmpx += GetFont(row->par, -2)
3930 .stringWidth(layout.labelsep);
3931 tmpx-= SingleWidth(row->par, c - 1);
3932 if (tmpx < left_margin)
3936 /* make sure that a last space in a row doesnt count */
3937 if (c > 0 && c >= last
3938 && row->par->IsLineSeparator(c - 1)
3939 && !(!row->next || row->next->par != row->par)) {
3940 tmpx -= SingleWidth(row->par, c - 1);
3941 tmpx -= fill_separator;
3950 /* turn the selection into a new environment. If there is no selection,
3951 * create an empty environment */
3952 void LyXText::InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind)
3954 /* no footnoteenvironment in a footnoteenvironment */
3955 if (cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3956 WriteAlert(_("Impossible operation"),
3957 _("You can't insert a float in a float!"),
3961 /* no marginpars in minipages */
3962 if (kind == LyXParagraph::MARGIN
3963 && cursor.par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
3964 WriteAlert(_("Impossible operation"),
3965 _("You can't insert a marginpar in a minipage!"),
3970 /* this doesnt make sense, if there is no selection */
3971 bool dummy_selection = false;
3973 sel_start_cursor = cursor; /* dummy selection */
3974 sel_end_cursor = cursor;
3975 dummy_selection = true;
3978 LyXParagraph *tmppar;
3980 if (sel_start_cursor.par->table || sel_end_cursor.par->table){
3981 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
3985 /* a test to make sure there is not already a footnote
3986 * in the selection. */
3988 tmppar = sel_start_cursor.par->ParFromPos(sel_start_cursor.pos);
3990 while (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos) &&
3991 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
3992 tmppar = tmppar->next;
3994 if (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)
3995 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3996 WriteAlert(_("Impossible operation"),
3997 _("Float would include float!"),
4002 /* ok we have a selection. This is always between sel_start_cursor
4003 * and sel_end cursor */
4005 SetUndo(Undo::FINISH,
4006 sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous,
4007 sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)->next);
4009 if (sel_end_cursor.pos > 0
4010 && sel_end_cursor.par->IsLineSeparator(sel_end_cursor.pos - 1))
4011 sel_end_cursor.pos--; /* please break before a space at
4013 if (sel_start_cursor.par == sel_end_cursor.par
4014 && sel_start_cursor.pos > sel_end_cursor.pos)
4015 sel_start_cursor.pos--;
4017 sel_end_cursor.par->BreakParagraphConservative(sel_end_cursor.pos);
4019 sel_end_cursor.par = sel_end_cursor.par->Next();
4020 sel_end_cursor.pos = 0;
4022 // don't forget to insert a dummy layout paragraph if necessary
4023 if (sel_start_cursor.par->GetLayout() != sel_end_cursor.par->layout){
4024 sel_end_cursor.par->BreakParagraphConservative(0);
4025 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4026 sel_end_cursor.par = sel_end_cursor.par->next;
4029 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4031 cursor = sel_end_cursor;
4033 /* please break behind a space, if there is one. The space should
4035 if (sel_start_cursor.pos > 0
4036 && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1))
4037 sel_start_cursor.pos--;
4038 if (sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) {
4039 sel_start_cursor.par->Erase(sel_start_cursor.pos);
4042 sel_start_cursor.par->BreakParagraphConservative(sel_start_cursor.pos);
4043 tmppar = sel_start_cursor.par->Next();
4045 if (dummy_selection) {
4047 if (kind == LyXParagraph::TAB
4048 || kind == LyXParagraph::FIG
4049 || kind == LyXParagraph::WIDE_TAB
4050 || kind == LyXParagraph::WIDE_FIG
4051 || kind == LyXParagraph::ALGORITHM) {
4052 int lay = textclasslist.NumberOfLayout(parameters->textclass,
4054 if (lay == -1) // layout not found
4055 // use default layout "Standard" (0)
4057 tmppar->SetLayout(lay);
4061 if (sel_start_cursor.pos > 0) {
4062 /* the footnote-environment should begin with a standard layout.
4063 * Imagine you insert a footnote within an enumeration, you
4064 * certainly do not want an enumerated footnote! */
4068 /* this is a exception the user would sometimes expect, I hope */
4069 sel_start_cursor.par->Clear();
4073 while (tmppar != sel_end_cursor.par) {
4074 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4075 tmppar->footnotekind = kind;
4076 tmppar = tmppar->Next();
4079 RedoParagraphs(sel_start_cursor, sel_end_cursor.par->Next());
4081 SetCursor(sel_start_cursor.par->Next(), 0);
4087 // returns pointer to a specified row
4088 Row * LyXText::GetRow(LyXParagraph * par,
4089 LyXParagraph::size_type pos, long & y) const
4094 if (par == currentrow->par || par == currentrow->par->Previous()) {
4095 // do not dereference par, it may have been deleted
4096 // already! (Matthias)
4097 while (currentrow->previous && currentrow->previous->par != par) {
4098 currentrow = currentrow->previous;
4099 currentrow_y -= currentrow->height;
4101 while (currentrow->previous && currentrow->previous->par == par) {
4102 currentrow = currentrow->previous;
4103 currentrow_y -= currentrow->height;
4106 tmprow = currentrow;
4108 // find the first row of the specified paragraph
4109 while (tmprow->next && (tmprow->par != par)) {
4110 y += tmprow->height;
4111 tmprow = tmprow->next;
4114 if (tmprow->par == par){
4115 // now find the wanted row
4116 while (tmprow->pos < pos && tmprow->next && tmprow->next->par == par &&
4117 tmprow->next->pos <= pos) {
4118 y += tmprow->height;
4119 tmprow = tmprow->next;
4121 currentrow = tmprow;
4128 // find the first row of the specified paragraph
4129 while (tmprow->next && (tmprow->par != par)) {
4130 y += tmprow->height;
4131 tmprow = tmprow->next;
4134 // now find the wanted row
4135 while (tmprow->pos < pos && tmprow->next && tmprow->next->par == par &&
4136 tmprow->next->pos <= pos) {
4137 y += tmprow->height;
4138 tmprow = tmprow->next;
4141 currentrow = tmprow;