1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright (C) 1995 Matthias Ettrich
7 * Copyright (C) 1995-1998 The LyX Team.
9 *======================================================*/
16 #pragma implementation "table.h"
20 #include "lyxparagraph.h"
22 #include "textutils.h"
23 #include "lyx_gui_misc.h"
26 #include "bufferparams.h"
28 #include "lyxscreen.h"
29 #include "minibuffer.h"
31 // $Id: text.C,v 1.1 1999/09/27 18:44:38 larsbj Exp $
33 #if !defined(lint) && !defined(WITH_WARNINGS)
34 static char vcid[] = "$Id: text.C,v 1.1 1999/09/27 18:44:38 larsbj Exp $";
38 static const int LYX_PAPER_MARGIN = 20;
40 extern int mono_video;
41 extern int reverse_video;
42 extern int fast_selection;
43 extern BufferView *current_view;
44 extern int UnlockInset(UpdatableInset* inset);
47 extern int bibitemMaxWidth(const class LyXFont &);
50 extern MiniBuffer *minibuffer;
52 int LyXText::SingleWidth(LyXParagraph *par, int pos)
54 char c = par->GetChar(pos);
55 return SingleWidth(par, pos, c);
59 int LyXText::SingleWidth(LyXParagraph *par, int pos, char c)
61 LyXFont font = GetFont(par, pos);
63 // The most common case is handled first (Asger)
67 } else if (IsHfillChar(c)) {
68 return 3; /* because of the representation
69 * as vertical lines */
71 } else if (c == LYX_META_FOOTNOTE ||
72 c == LYX_META_MARGIN ||
75 c == LYX_META_WIDE_FIG ||
76 c == LYX_META_WIDE_TAB ||
77 c == LYX_META_ALGORITHM)
90 case LYX_META_ALGORITHM:
93 case LYX_META_WIDE_FIG:
96 case LYX_META_WIDE_TAB:
99 case LYX_META_FOOTNOTE:
105 return font.stringWidth(fs);
108 else if (c == LYX_META_INSET) {
109 Inset *tmpinset=par->GetInset(pos);
111 return par->GetInset(pos)->Width(font);
115 } else if (IsSeparatorChar(c))
117 else if (IsNewlineChar(c))
119 return font.width(c);
123 /* returns the paragraph position of the last character in the
125 int LyXText::RowLast(Row *row)
127 if (row->next == NULL)
128 return row->par->Last()-1;
129 else if (row->next->par != row->par)
130 return row->par->Last()-1;
132 return row->next->pos - 1;
136 void LyXText::Draw(Row *row, int &pos, LyXScreen &scr, int offset, float &x)
138 char c = row->par->GetChar(pos);
140 if (IsNewlineChar(c)) {
142 // Draw end-of-line marker
144 LyXFont font = GetFont(row->par, pos);
145 int asc = font.maxAscent();
146 int wid = font.width('n');
147 int y = (offset + row->baseline);
149 p[0].x = int(x + wid*0.375); p[0].y = int(y - 0.875*asc*0.75);
150 p[1].x = int(x); p[1].y = int(y - 0.500*asc*0.75);
151 p[2].x = int(x + wid*0.375); p[2].y = int(y - 0.125*asc*0.75);
152 scr.drawLines(::getGC(gc_new_line),p, 3);
154 p[0].x = int(x); p[0].y = int(y - 0.500*asc*0.75);
155 p[1].x = int(x + wid); p[1].y = int(y - 0.500*asc*0.75);
156 p[2].x = int(x + wid); p[2].y = int(y - asc*0.75);
157 scr.drawLines(::getGC(gc_new_line),p, 3);
161 LyXFont font = GetFont(row->par, pos);
162 LyXFont font2 = font;
164 if (c == LYX_META_FOOTNOTE ||
165 c == LYX_META_MARGIN ||
168 c == LYX_META_WIDE_FIG ||
169 c == LYX_META_WIDE_TAB ||
170 c == LYX_META_ALGORITHM) {
173 case LYX_META_MARGIN:
175 /* draw a sign at the left margin! */
176 scr.drawText(font, "!", 1, offset + row->baseline,
177 (LYX_PAPER_MARGIN - font.width('!'))/2);
185 case LYX_META_ALGORITHM:
188 case LYX_META_WIDE_FIG:
191 case LYX_META_WIDE_TAB:
194 case LYX_META_FOOTNOTE:
201 /* calculate the position of the footnotemark */
202 int y = (row->baseline - font2.maxAscent()
205 font.setColor(LyXFont::INSET);
209 /* draw it and set new x position */
210 x += scr.drawString(font, fs, offset + y, int(x));
212 scr.drawLine(gc_foot, offset + row->baseline,
213 int(tmpx), int(x - tmpx));
217 } else if (c == LYX_META_INSET) {
218 Inset *tmpinset = row->par->GetInset(pos);
220 tmpinset->Draw(font, scr, offset + row->baseline, x);
225 /* usual characters, no insets */
227 // Collect character that we can draw in one command
229 // This is dirty, but fast. Notice that it will never be too small.
230 // For the record, I'll note that Microsoft Word has a limit
231 // of 768 here. We have none :-) (Asger)
232 static char textstring[1024];
234 int last = RowLast(row);
235 // Prevent crash in the extremely unlikely event
236 // that our array is too small
237 if (last > pos+1020) last = pos + 1020;
244 while (pos <= last &&
245 (unsigned char) (c = row->par->GetChar(pos)) > ' ' &&
246 font2 == GetFont(row->par, pos)) {
254 // If monochrome and LaTeX mode, provide reverse background
255 if (mono_video && font.latex() == LyXFont::ON) {
256 int a=font.maxAscent(), d=font.maxDescent();
257 scr.fillRectangle(gc_copy, int(tmpx), offset + row->baseline-a,
258 font.textWidth(textstring, i), a+d);
261 /* Draw text and set the new x position */
262 x += scr.drawText(font, textstring, i, offset + row->baseline,
264 /* what about underbars? */
265 if (font.underbar() == LyXFont::ON && font.latex() != LyXFont::ON) {
266 scr.drawLine(gc_copy, offset + row->baseline + 2,
267 int(tmpx), int(x - tmpx));
270 // If we want ulem.sty support, drawing
271 // routines should go here. (Asger)
272 // Why shouldn't LyXFont::drawText handle it internally?
276 /* Returns the left beginning of the text.
277 * This information cannot be taken from the layouts-objekt, because in
278 * LaTeX the beginning of the text fits in some cases (for example sections)
279 * exactly the label-width. */
280 int LyXText::LeftMargin(Row* row)
285 LyXParagraph *newpar;
287 layout = lyxstyle.Style(parameters->textclass, row->par->GetLayout());
289 LString parindent = layout->parindent;
291 /* table stuff -- begin*/
294 /* table stuff -- end*/
296 x = LYX_PAPER_MARGIN;
298 x += lyxstyle.TextClass(parameters->textclass)->
299 defaultfont.signedStringWidth(lyxstyle.TextClass(parameters->textclass)->leftmargin);
301 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
302 LyXFont font(LyXFont::ALL_SANE);
303 font.setSize(LyXFont::SIZE_SMALL);
304 x += font.textWidth("Mwide-figM", 10) + LYX_PAPER_MARGIN/2;
307 /* this is the way, LyX handles the LaTeX-Environments.
308 * I have had this idea very late, so it seems to be a
309 * later added hack and this is true */
310 if (!row->par->GetDepth()) {
311 if (!row->par->GetLayout()) {
312 /* find the previous same level paragraph */
313 if (row->par->FirstPhysicalPar()->Previous()) {
314 newpar = row->par->DepthHook(row->par->GetDepth());
315 if (newpar && lyxstyle.Style(parameters->textclass, newpar->GetLayout())->nextnoindent)
321 /* find the next level paragraph */
323 newpar = row->par->DepthHook(row->par->GetDepth()-1);
325 /* make a corresponding row. Needed to call LeftMargin() */
327 /* check wether it is a sufficent paragraph */
328 if (newpar && newpar->footnoteflag == row->par->footnoteflag
329 && lyxstyle.Style(parameters->textclass,
330 newpar->GetLayout())->isEnvironment()) {
331 dummyrow.par = newpar;
332 dummyrow.pos = newpar->Last();
333 x = LeftMargin(&dummyrow);
336 /* this is no longer an error, because this function is used
337 * to clear impossible depths after changing a layout. Since there
338 * is always a redo, LeftMargin() is always called */
340 /* printf("LYX_ERROR (text, LeftMargin()) impossible depth \n");*/
341 row->par->FirstPhysicalPar()->depth = 0;
344 if (newpar && !row->par->GetLayout()) {
345 if (newpar->FirstPhysicalPar()->noindent)
348 parindent = lyxstyle.Style(parameters->textclass,
349 newpar->GetLayout())->parindent;
354 labelfont = GetFont(row->par, -2);
355 switch (layout->margintype) {
357 if (!layout->leftmargin.empty()) {
358 x += lyxstyle.TextClass(parameters->textclass)->defaultfont.signedStringWidth(layout->leftmargin);
360 if (!row->par->GetLabelString().empty()) {
361 x += labelfont.signedStringWidth(layout->labelindent);
362 x += labelfont.stringWidth(row->par->GetLabelString());
363 x += labelfont.stringWidth(layout->labelsep);
367 x += labelfont.signedStringWidth(layout->labelindent);
368 if (row->pos >= BeginningOfMainBody(row->par)) {
369 if (!row->par->GetLabelWidthString().empty()) {
370 x += labelfont.stringWidth(row->par->GetLabelWidthString());
371 x += labelfont.stringWidth(layout->labelsep);
376 x += ( lyxstyle.TextClass(parameters->textclass)->defaultfont.signedStringWidth(layout->leftmargin) * 4
377 / (row->par->GetDepth() + 4));
379 case MARGIN_FIRST_DYNAMIC:
380 if (layout->labeltype == LABEL_MANUAL) {
381 if (row->pos >= BeginningOfMainBody(row->par)) {
382 x += labelfont.signedStringWidth(layout->leftmargin);
384 x += labelfont.signedStringWidth(layout->labelindent);
388 // Special case to fix problems with theorems (JMarc)
389 || (layout->labeltype == LABEL_STATIC
390 && layout->latextype == LATEX_ENVIRONMENT
391 && ! row->par->IsFirstInSequence())) {
392 x += labelfont.signedStringWidth(layout->leftmargin);
393 } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
394 && layout->labeltype != LABEL_BIBLIO
395 && layout->labeltype != LABEL_CENTERED_TOP_ENVIRONMENT) {
396 x += labelfont.signedStringWidth(layout->labelindent);
397 x += labelfont.stringWidth(layout->labelsep);
398 x += labelfont.stringWidth(row->par->GetLabelString());
403 case MARGIN_RIGHT_ADDRESS_BOX:
405 /* ok, a terrible hack. The left margin depends on the widest row
406 * in this paragraph. Do not care about footnotes, they are *NOT*
407 * allowed in the LaTeX realisation of this layout. */
409 /* find the first row of this paragraph */
411 while (tmprow->previous && tmprow->previous->par == row->par)
412 tmprow = tmprow->previous;
414 int minfill = tmprow->fill;
415 while (tmprow-> next && tmprow->next->par == row->par) {
416 tmprow = tmprow->next;
417 if (tmprow->fill < minfill)
418 minfill = tmprow->fill;
421 x += lyxstyle.TextClass(parameters->textclass)->defaultfont.signedStringWidth(layout->leftmargin);
426 if (row->par->pextra_type == PEXTRA_INDENT) {
427 if (!row->par->pextra_widthp.empty()) {
428 x += paperwidth * atoi(row->par->pextra_widthp.c_str()) / 100;
429 } else if (!row->par->pextra_width.empty()) {
430 int xx = VSpace(row->par->pextra_width).inPixels();
433 xx = paperwidth * 80 / 100;
435 } else { // should not happen
436 LyXFont font(LyXFont::ALL_SANE);
437 x += font.stringWidth("XXXXXX");
442 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
443 align = layout->align;
445 align = row->par->FirstPhysicalPar()->align;
447 /* set the correct parindent */
449 if ((layout->labeltype == LABEL_NO_LABEL
450 || layout->labeltype == LABEL_TOP_ENVIRONMENT
451 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
452 || (layout->labeltype == LABEL_STATIC
453 && layout->latextype == LATEX_ENVIRONMENT
454 && ! row->par->IsFirstInSequence()))
455 && row->par == row->par->FirstPhysicalPar()
456 && align == LYX_ALIGN_BLOCK
457 && !row->par->noindent
458 && (row->par->layout ||
459 parameters->paragraph_separation == LYX_PARSEP_INDENT))
460 x += lyxstyle.TextClass(parameters->textclass)->defaultfont.stringWidth(parindent);
462 if (layout->labeltype==LABEL_BIBLIO) { // ale970405 Right width for bibitems
463 x += bibitemMaxWidth(lyxstyle.TextClass(parameters->textclass)->defaultfont);
471 int LyXText::RightMargin(Row *row)
476 LyXParagraph *newpar;
478 layout = lyxstyle.Style(parameters->textclass, row->par->GetLayout());
480 x = LYX_PAPER_MARGIN;
482 x += lyxstyle.TextClass(parameters->textclass)->
483 defaultfont.signedStringWidth(lyxstyle.TextClass(parameters->textclass)->rightmargin);
484 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
485 x += LYX_PAPER_MARGIN/2;
488 /* this is the way, LyX handles the LaTeX-Environments.
489 * I have had this idea very late, so it seems to be a
490 * later added hack and this is true */
491 if (row->par->GetDepth()) {
492 /* find the next level paragraph */
497 newpar = newpar->FirstPhysicalPar()->Previous();
499 newpar = newpar->FirstPhysicalPar();
500 } while (newpar && newpar->GetDepth() >= row->par->GetDepth()
501 && newpar->footnoteflag == row->par->footnoteflag);
503 /* make a corresponding row. Needed to call LeftMargin() */
505 /* check wether it is a sufficent paragraph */
506 if (newpar && newpar->footnoteflag == row->par->footnoteflag
507 && lyxstyle.Style(parameters->textclass,
508 newpar->GetLayout())->isEnvironment()) {
509 dummyrow.par = newpar;
511 x = RightMargin(&dummyrow);
514 /* this is no longer an error, because this function is used
515 * to clear impossible depths after changing a layout. Since there
516 * is always a redo, LeftMargin() is always called */
518 /* printf("LYX_ERROR (text, LeftMargin()) impossible depth \n");*/
519 row->par->FirstPhysicalPar()->depth = 0;
523 //fprintf(stderr,"rightmargin: %s\n", layout->rightmargin.c_str());
525 x += (lyxstyle.TextClass(parameters->textclass)->defaultfont.signedStringWidth(layout->rightmargin) * 4
526 / (row->par->GetDepth() + 4));
532 int LyXText::LabelEnd (Row *row)
534 if (lyxstyle.Style(parameters->textclass, row->par->GetLayout())->margintype == MARGIN_MANUAL) {
537 tmprow.pos = row->par->Last();
538 return LeftMargin(&tmprow); /* just the beginning
539 * of the main body */
542 return 0; /* LabelEnd is only needed, if the
543 * layout fills a flushleft
548 /* table stuff -- begin*/
549 int LyXText::NumberOfCell(LyXParagraph *par, int pos)
553 while (tmp_pos < pos) {
554 if (par->IsNewline(tmp_pos))
562 int LyXText::WidthOfCell(LyXParagraph *par, int &pos)
565 while (pos < par->Last() && !par->IsNewline(pos)) {
566 w += SingleWidth(par, pos);
569 if (par->IsNewline(pos))
575 char LyXText::HitInTable(Row* row, int x)
578 float fill_separator, fill_hfill, fill_label_hfill;
579 if (!row->par->table)
581 PrepareToPrint(row, tmpx, fill_separator, fill_hfill, fill_label_hfill);
582 return (x > tmpx && x < tmpx + row->par->table->WidthOfTable());
586 bool LyXText::MouseHitInTable(int x, long y)
588 Row *row = GetRowNearY(y);
589 return HitInTable(row, x);
593 /* table stuff -- end*/
596 /* get the next breakpoint in a given paragraph */
597 int LyXText::NextBreakPoint(Row* row, int width)
600 int last_separator = -1; /* position of the last possible breakpoint
601 * -1 isn't a suitable value, but a flag */
605 LyXParagraph *par = row->par;
608 /* table stuff -- begin*/
611 && (!par->IsNewline(pos)
612 || !par->table->IsFirstCell(NumberOfCell(par, pos+1)))) {
613 if (par->GetChar(pos) == LYX_META_INSET &&
614 par->GetInset(pos) && par->GetInset(pos)->Display()){
615 par->GetInset(pos)->SetDisplay(false);
621 /* table stuff -- end*/
623 left_margin = LabelEnd(row);
624 width -= RightMargin(row);
625 int main_body = BeginningOfMainBody(par);
626 LyXLayout* layout = lyxstyle.Style(parameters->textclass, par->GetLayout());
630 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
631 /* special code for right address boxes, only newlines count */
632 while (i < par->Last()) {
633 if (par->IsNewline(i)) {
635 i = par->Last() - 1;/* this means break */
637 } else if (par->GetChar(i) == LYX_META_INSET &&
638 par->GetInset(i) && par->GetInset(i)->Display()){
639 par->GetInset(i)->SetDisplay(false);
644 // Last position is an invariant
645 int const last = par->Last();
646 /* this is the usual handling */
648 while (x < width && i < last) {
650 if (IsNewlineChar(c)) {
652 x = width; /* this means break */
653 } else if (c == LYX_META_INSET &&
654 par->GetInset(i) && par->GetInset(i)->Display()){
655 /* check wether a Display() inset is valid here .
656 if not, change it to non-display*/
657 if (layout->isCommand()
658 || (layout->labeltype == LABEL_MANUAL
659 && i < BeginningOfMainBody(par))){
660 /* display istn't allowd */
661 par->GetInset(i)->SetDisplay(false);
662 x += SingleWidth(par, i, c);
664 /* inset is display. So break the line here */
668 if (IsLineSeparatorChar(par->GetChar(i+1)))
671 last_separator = last; // to avoid extra rows
673 last_separator = i - 1;
674 x = width; /* this means break */
677 if (IsLineSeparatorChar(c))
679 x += SingleWidth(par, i, c);
682 if (i == main_body) {
683 x += GetFont(par, -2).stringWidth(layout->labelsep);
684 if (par->IsLineSeparator(i - 1))
685 x-= SingleWidth(par, i - 1);
690 /* end of paragraph is always a suitable separator */
691 if (i == last && x < width)
695 /* well, if last_separator is still 0, the line isn't breakable.
696 * don't care and cut simply at the end */
697 if (last_separator < 0) {
701 /* manual labels cannot be broken in LaTeX, do not care */
702 if (main_body && last_separator < main_body)
703 last_separator = main_body - 1;
705 return last_separator;
709 /* returns the minimum space a row needs on the screen in pixel */
710 int LyXText::Fill(Row *row, int paperwidth)
712 int w,i, last, fill, left_margin;
713 /* get the pure distance */
716 /* table stuff -- begin*/
717 if (row->par->table) {
718 /* for tables FILL does calculate the widthes of each cell in
721 int cell = NumberOfCell(row->par, pos);
724 row->par->table->SetWidthOfCell(cell, WidthOfCell(row->par, pos));
726 } while (pos <= last && !row->par->table->IsFirstCell(cell));
727 /* don't forget the very last table cell without characters */
728 if (cell == row->par->table->GetNumberOfCells()-1)
729 row->par->table->SetWidthOfCell(cell, WidthOfCell(row->par, pos));
731 return 0; /* width of table cannot be returned since
732 * we cannot guarantee its correct value at
735 /* table stuff -- end*/
737 left_margin = LabelEnd(row);
739 /* if the row ends with newline, this newline will not be relevant */
740 if (last >= 0 && row->par->IsNewline(last))
743 /* if the row ends with a space, this space will not be relevant */
744 if (last >= 0 && row->par->IsLineSeparator(last))
747 /* special handling of the right address boxes */
748 if (lyxstyle.Style(parameters->textclass, row->par->GetLayout())->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
749 int tmpfill = row->fill;
750 row->fill = 0; /* the minfill in MarginLeft() */
754 /* the old way, impossible when using environments: */
755 /* w = LyXStringWidth(lyxstyle.Style(parameters->textclass, row->par->GetLayout())->font, */
756 /* lyxstyle.Style(parameters->textclass, row->par->GetLayout())->leftmargin); */
761 int main_body = BeginningOfMainBody(row->par);
762 LyXLayout *layout = lyxstyle.Style(parameters->textclass,
763 row->par->GetLayout());
766 w += SingleWidth(row->par, i);
768 if (i == main_body) {
769 w += GetFont(row->par, -2).stringWidth(layout->labelsep);
770 if (row->par->IsLineSeparator(i - 1))
771 w-= SingleWidth(row->par, i - 1);
777 fill = paperwidth - w - RightMargin(row);
782 /* returns the minimum space a manual label needs on the screen in pixel */
783 int LyXText::LabelFill(Row *row)
788 last = BeginningOfMainBody(row->par) - 1;
789 /* -1 because a label ends either with a space that is in the label,
790 * or with the beginning of a footnote that is outside the label. */
792 // I don't understand this code in depth, but sometimes "last" is less than
793 // 0 and this causes a crash. This fix seems to work correctly, but I
794 // bet the real error is elsewhere. The bug is triggered when you have an
795 // open footnote in a paragraph environment with a manual label. (Asger)
796 if (last<0) last = 0;
798 if (row->par->IsLineSeparator(last)) /* a sepearator at this end
805 w += SingleWidth(row->par, i);
809 if (!row->par->labelwidthstring.empty()) {
810 fill = GetFont(row->par, -2).stringWidth(row->par->labelwidthstring) - w;
820 /* returns the number of separators in the specified row. The separator
821 * on the very last column doesnt count */
822 int LyXText::NumberOfSeparators(Row *row)
829 int main_body = BeginningOfMainBody(row->par);
832 for (; p < last; p++) {
833 if (row->par->IsSeparator(p)) {
841 /* returns the number of hfills in the specified row. The LyX-Hfill is
842 * a LaTeX \hfill so that the hfills at the beginning and at the end were
843 * ignored. This is *MUCH* more usefull than not to ignore! */
844 int LyXText::NumberOfHfills(Row *row)
850 if (first) { /* hfill *DO* count at the beginning
852 while(first <= last && row->par->IsHfill(first))
857 int main_body = BeginningOfMainBody(row->par);
858 if (first < main_body)
860 for (p = first; p <= last; p++) { /* last, because the end is ignored! */
861 if (row->par->IsHfill(p)) {
869 /* like NumberOfHfills, but only those in the manual label! */
870 int LyXText::NumberOfLabelHfills(Row *row)
876 if (first) { /* hfill *DO* count at the beginning
878 while(first < last && row->par->IsHfill(first))
883 int main_body = BeginningOfMainBody(row->par);
885 if (last > main_body)
888 for (p = first; p < last; p++) { /* last, because the end is ignored! */
889 if (row->par->IsHfill(p)) {
897 /* returns true, if a expansion is needed.
898 * Rules are given by LaTeX */
899 bool LyXText::HfillExpansion(Row *row_ptr, int pos)
901 /* by the way, is it a hfill? */
902 if (!row_ptr->par->IsHfill(pos))
905 /* at the end of a row it does not count */
906 if (pos >= RowLast(row_ptr))
909 /* at the beginning of a row it does not count, if it is not
910 * the first row of a paragaph */
914 /* in some labels it does not count */
915 if ( lyxstyle.Style(parameters->textclass, row_ptr->par->GetLayout())->margintype != MARGIN_MANUAL &&
916 pos < BeginningOfMainBody(row_ptr->par))
919 /* if there is anything between the first char of the row and
920 * the sepcified position that is not a newline and not a hfill,
921 * the hfill will count, otherwise not */
923 int i = row_ptr->pos;
924 while (i < pos && (row_ptr->par->IsNewline(i)
925 || row_ptr->par->IsHfill(i)))
932 void LyXText::SetHeightOfRow(Row *row_ptr)
934 /* get the maximum ascent and the maximum descent */
935 int asc, maxasc, desc, maxdesc, pos_end, pos, labeladdon;
937 float layoutdesc = 0;
939 LyXParagraph *par, *firstpar;
943 /* this must not happen before the currentrow for clear reasons.
944 so the trick is just to set the current row onto this row */
946 GetRow(row_ptr->par, row_ptr->pos, unused_y);
948 /* ok , let us initialize the maxasc and maxdesc value.
949 * This depends in LaTeX of the font of the last character
950 * in the paragraph. The hack below is necessary because
951 * of the possibility of open footnotes */
953 /* Correction: only the fontsize count. The other properties
954 are taken from the layoutfont. Nicer on the screen :) */
956 par = row_ptr->par->LastPhysicalPar();
957 firstpar = row_ptr->par->FirstPhysicalPar();
959 LyXLayout *layout = lyxstyle.Style(parameters->textclass, firstpar->GetLayout());
961 LyXFont font = GetFont(par, par->Last()-1);
962 LyXFont::FONT_SIZE size = font.size();
963 font = GetFont(par, -1);
966 LyXFont labelfont = GetFont(par, -2);
968 maxasc = int(font.maxAscent() *
969 layout->spacing.getValue() *
970 parameters->spacing.getValue());
971 maxdesc = int(font.maxDescent() *
972 layout->spacing.getValue() *
973 parameters->spacing.getValue());
975 pos_end = RowLast(row_ptr);
979 // Check if any insets are larger
980 for (pos = row_ptr->pos; pos <= pos_end; pos++) {
981 if (row_ptr->par->GetChar(pos) == LYX_META_INSET) {
982 tmpfont = GetFont(row_ptr->par, pos);
983 tmpinset = row_ptr->par->GetInset(pos);
985 asc = tmpinset->Ascent(tmpfont);
986 desc = tmpinset->Descent(tmpfont);
995 // Check if any custom fonts are larger (Asger)
996 // This is not completely correct, but we can live with the small,
997 // cosmetic error for now.
998 LyXFont::FONT_SIZE maxsize = row_ptr->par->HighestFontInRange(row_ptr->pos, pos_end);
999 if (maxsize > font.size()) {
1000 font.setSize(maxsize);
1002 asc = font.maxAscent();
1003 desc = font.maxDescent();
1010 /* table stuff -- begin*/
1011 if (row_ptr->par->table){
1012 // stretch the rows a bit
1016 /* table stuff -- end*/
1018 // This is nicer with box insets:
1022 row_ptr->ascent_of_text = maxasc;
1024 /* is it a top line? */
1025 if (row_ptr->pos == 0
1026 && row_ptr->par == firstpar) {
1028 /* some parksips VERY EASY IMPLEMENTATION */
1029 if (parameters->paragraph_separation == LYX_PARSEP_SKIP) {
1030 if (layout->isParagraph()
1031 && firstpar->GetDepth() == 0
1032 && firstpar->Previous())
1033 maxasc += parameters->getDefSkip().inPixels();
1034 else if (firstpar->Previous()
1035 && lyxstyle.Style(parameters->textclass,
1036 firstpar->Previous()->GetLayout())->isParagraph()
1037 && firstpar->Previous()->GetDepth() == 0)
1038 // is it right to use defskip here too? (AS)
1039 maxasc += parameters->getDefSkip().inPixels();
1042 /* the paper margins */
1043 if (!row_ptr->par->previous)
1044 maxasc += LYX_PAPER_MARGIN;
1046 /* add the vertical spaces, that the user added */
1047 if (firstpar->added_space_top.kind() != VSpace::NONE)
1048 maxasc += int(firstpar->added_space_top.inPixels());
1050 /* do not forget the DTP-lines!
1051 * there height depends on the font of the nearest character */
1052 if (firstpar->line_top)
1053 maxasc += 2 * GetFont(firstpar, 0).ascent('x');
1055 /* and now the pagebreaks */
1056 if (firstpar->pagebreak_top)
1057 maxasc += 3 * DefaultHeight();
1059 /* this is special code for the chapter, since the label of this
1060 * layout is printed in an extra row */
1061 if (layout->labeltype == LABEL_COUNTER_CHAPTER
1062 && parameters->secnumdepth>=0) {
1063 labeladdon = int(labelfont.maxDescent() *
1064 layout->spacing.getValue() *
1065 parameters->spacing.getValue())
1066 + int(labelfont.maxAscent() *
1067 layout->spacing.getValue() *
1068 parameters->spacing.getValue());
1071 /* special code for the top label */
1072 if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
1073 || layout->labeltype == LABEL_BIBLIO
1074 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1075 && row_ptr->par->IsFirstInSequence()
1076 && !row_ptr->par->GetLabelString().empty()) {
1078 (labelfont.maxAscent() *
1079 layout->spacing.getValue() *
1080 parameters->spacing.getValue())
1081 +(labelfont.maxDescent() *
1082 layout->spacing.getValue() *
1083 parameters->spacing.getValue())
1084 + layout->topsep * DefaultHeight()
1085 + layout->labelbottomsep * DefaultHeight());
1088 /* and now the layout spaces, for example before and after a section,
1089 * or between the items of a itemize or enumerate environment */
1091 if (!firstpar->pagebreak_top) {
1092 LyXParagraph *prev = row_ptr->par->Previous();
1094 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth());
1095 if (prev && prev->GetLayout() == firstpar->GetLayout()
1096 && prev->GetDepth() == firstpar->GetDepth()
1097 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1099 layoutasc = (layout->itemsep * DefaultHeight());
1101 else if (row_ptr->previous) {
1102 tmptop = layout->topsep;
1104 if (row_ptr->previous->par->GetDepth() >= row_ptr->par->GetDepth())
1105 tmptop-=lyxstyle.Style(parameters->textclass, row_ptr->previous->par->GetLayout())->bottomsep;
1108 layoutasc = (tmptop * DefaultHeight());
1110 else if (row_ptr->par->line_top){
1111 tmptop = layout->topsep;
1114 layoutasc = (tmptop * DefaultHeight());
1117 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth()-1);
1119 maxasc += int(lyxstyle.Style(parameters->textclass,
1120 prev->GetLayout())->parsep * DefaultHeight());
1123 if (firstpar->Previous()
1124 && firstpar->Previous()->GetDepth() == 0
1125 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1128 else if (firstpar->Previous()){
1129 maxasc += int(layout->parsep * DefaultHeight());
1135 /* is it a bottom line? */
1136 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
1137 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
1139 /* the paper margins */
1141 maxdesc += LYX_PAPER_MARGIN;
1143 /* add the vertical spaces, that the user added */
1144 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1145 maxdesc += int(firstpar->added_space_bottom.inPixels());
1147 /* do not forget the DTP-lines!
1148 * there height depends on the font of the nearest character */
1149 if (firstpar->line_bottom)
1150 maxdesc += 2 * (GetFont(par, par->Last()-1).ascent('x'));
1152 /* and now the pagebreaks */
1153 if (firstpar->pagebreak_bottom)
1154 maxdesc += 3 * DefaultHeight();
1156 /* and now the layout spaces, for example before and after a section,
1157 * or between the items of a itemize or enumerate environment */
1158 if (!firstpar->pagebreak_bottom && row_ptr->par->Next()) {
1159 LyXParagraph *nextpar = row_ptr->par->Next();
1160 LyXParagraph *comparepar = row_ptr->par;
1164 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1165 usual = (lyxstyle.Style(parameters->textclass, comparepar->GetLayout())->bottomsep * DefaultHeight());
1166 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1167 if (comparepar->GetLayout()!=nextpar->GetLayout()
1168 || nextpar->GetLabelWidthString() !=
1169 comparepar->GetLabelWidthString())
1170 unusual = (lyxstyle.Style(parameters->textclass, comparepar->GetLayout())->bottomsep * DefaultHeight());
1172 if (unusual > usual)
1173 layoutdesc = unusual;
1177 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1179 if (comparepar->GetLayout()!= nextpar->GetLayout()
1180 || nextpar->GetLabelWidthString() !=
1181 comparepar->GetLabelWidthString())
1182 layoutdesc = int(lyxstyle.Style(parameters->textclass, comparepar->GetLayout())->bottomsep * DefaultHeight());
1187 /* incalculate the layout spaces */
1188 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1189 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1191 /* table stuff -- begin*/
1192 if (row_ptr->par->table){
1193 maxasc += row_ptr->par->table->
1194 AdditionalHeight(NumberOfCell(row_ptr->par, row_ptr->pos));
1196 /* table stuff -- end*/
1198 /* calculate the new height of the text */
1199 height -= row_ptr->height;
1201 row_ptr->height=maxasc+maxdesc+labeladdon;
1202 row_ptr->baseline=maxasc+labeladdon;
1204 height += row_ptr->height;
1208 /* Appends the implicit specified paragraph behind the specified row,
1209 * start at the implicit given position */
1210 void LyXText::AppendParagraph(Row *row)
1214 bool not_ready = true;
1216 // Get the width of the row
1219 // The last character position of a paragraph is an invariant so we can
1220 // safely get it here. (Asger)
1221 int lastposition = row->par->Last();
1224 // Get the next breakpoint
1225 z = NextBreakPoint(row, paperwidth);
1229 // Insert the new row
1230 if (z < lastposition) {
1232 InsertRow(row, row->par, z);
1239 // Set the dimensions of the row
1240 tmprow->fill = Fill(tmprow, paperwidth);
1241 SetHeightOfRow(tmprow);
1243 } while (not_ready);
1247 void LyXText::BreakAgain(Row *row)
1252 Row *tmprow, *tmprow2;
1257 /* get the next breakpoint */
1258 z = NextBreakPoint(row, paperwidth);
1262 if (z < row->par->Last() ) {
1263 if (!row->next || (row->next && row->next->par != row->par)) {
1264 /* insert a new row */
1266 InsertRow(row, row->par, z);
1274 not_ready = 0; /* the rest will not change */
1281 /* if there are some rows too much, delete them */
1282 /* only if you broke the whole paragraph! */
1284 while (tmprow2->next && tmprow2->next->par == row->par) {
1285 tmprow2 = tmprow2->next;
1287 while (tmprow2 != row) {
1288 tmprow2 = tmprow2->previous;
1289 RemoveRow(tmprow2->next);
1294 /* set the dimensions of the row */
1295 tmprow->fill = Fill(tmprow, paperwidth);
1296 SetHeightOfRow(tmprow);
1297 } while (not_ready);
1301 /* this is just a little changed version of break again */
1302 void LyXText::BreakAgainOneRow(Row *row)
1307 Row *tmprow, *tmprow2;
1311 /* get the next breakpoint */
1312 z = NextBreakPoint(row, paperwidth);
1316 if (z < row->par->Last() ) {
1317 if (!row->next || (row->next && row->next->par != row->par)) {
1318 /* insert a new row */
1320 InsertRow(row, row->par, z);
1328 not_ready = 0; /* the rest will not change */
1335 /* if there are some rows too much, delete them */
1336 /* only if you broke the whole paragraph! */
1338 while (tmprow2->next && tmprow2->next->par == row->par) {
1339 tmprow2 = tmprow2->next;
1341 while (tmprow2 != row) {
1342 tmprow2 = tmprow2->previous;
1343 RemoveRow(tmprow2->next);
1348 /* set the dimensions of the row */
1349 tmprow->fill = Fill(tmprow, paperwidth);
1350 SetHeightOfRow(tmprow);
1354 void LyXText::BreakParagraph(char keep_layout)
1356 LyXLayout *layout = lyxstyle.Style(parameters->textclass,
1357 cursor.par->GetLayout());
1359 /* table stuff -- begin*/
1360 if (cursor.par->table) {
1361 // breaking of tables is only allowed at the beginning or the end */
1362 if (cursor.pos && cursor.pos < cursor.par->last &&
1363 !cursor.par->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par, cursor.pos)))
1364 return; /* no breaking of tables allowed */
1366 /* table stuff -- end*/
1368 /* this is only allowed, if the current paragraph is not empty or caption*/
1369 if ((cursor.par->Last() <= 0 && !cursor.par->IsDummy())
1371 layout->labeltype!=LABEL_SENSITIVE)
1374 SetUndo(Undo::INSERT,
1375 cursor.par->ParFromPos(cursor.pos)->previous,
1376 cursor.par->ParFromPos(cursor.pos)->next);
1378 /* table stuff -- begin*/
1379 if (cursor.par->table) {
1380 int cell = NumberOfCell(cursor.par, cursor.pos);
1381 if (cursor.par->table->ShouldBeVeryLastCell(cell))
1382 SetCursor(cursor.par,cursor.par->last);
1384 /* table stuff -- end*/
1385 /* please break alway behind a space */
1386 if (cursor.pos < cursor.par->Last()
1387 && cursor.par->IsLineSeparator(cursor.pos))
1390 /* break the paragraph */
1394 keep_layout = layout->isEnvironment();
1395 cursor.par->BreakParagraph(cursor.pos, keep_layout);
1397 /* table stuff -- begin*/
1398 if (cursor.par->table){
1399 // the table should stay with the contents
1401 cursor.par->Next()->table = cursor.par->table;
1402 cursor.par->table = NULL;
1405 /* table stuff -- end*/
1407 /* well this is the caption hack since one caption is really enough */
1408 if (layout->labeltype == LABEL_SENSITIVE){
1410 cursor.par->SetLayout(0); /* set the new paragraph to standard-layout */
1412 cursor.par->Next()->SetLayout(0); /* set the new paragraph to standard-layout */
1416 /* if the cursor is at the beginning of a row without prior newline,
1418 * This touches only the screen-update. Otherwise we would may have
1419 * an empty row on the screen */
1420 if (cursor.pos && !cursor.row->par->IsNewline(cursor.row->pos -1) &&
1421 cursor.row->pos == cursor.pos) {
1425 status = LyXText::NEED_MORE_REFRESH;
1426 refresh_row = cursor.row;
1427 refresh_y = cursor.y - cursor.row->baseline;
1429 /* Do not forget the special right address boxes */
1430 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1431 while (refresh_row->previous &&
1432 refresh_row->previous->par == refresh_row->par) {
1433 refresh_row = refresh_row->previous;
1434 refresh_y -= refresh_row->height;
1437 RemoveParagraph(cursor.row);
1439 /* set the dimensions of the cursor row */
1440 cursor.row->fill = Fill(cursor.row, paperwidth);
1442 SetHeightOfRow(cursor.row);
1444 while (!cursor.par->Next()->table && cursor.par->Next()->Last()
1445 && cursor.par->Next()->IsNewline(0))
1446 cursor.par->Next()->Erase(0);
1448 InsertParagraph(cursor.par->Next(), cursor.row);
1450 UpdateCounters(cursor.row->previous);
1452 /* this check is necessary. Otherwise the new empty paragraph will
1453 * be deleted automatically. And it is more friendly for the user! */
1455 SetCursor(cursor.par->Next(), 0);
1457 SetCursor(cursor.par, 0);
1459 if (cursor.row->next)
1460 BreakAgain(cursor.row->next);
1462 need_break_row = NULL;
1466 void LyXText::OpenFootnote()
1468 LyXParagraph *par, *endpar,*tmppar;
1471 par = cursor.par->ParFromPos(cursor.pos);
1473 /* if there is no footnote in this paragraph, just return. */
1475 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1478 /* ok, move the cursor right before the footnote */
1480 /* just a little faster than using CursorRight() */
1481 for (cursor.pos=0; cursor.par->ParFromPos(cursor.pos)!=par; cursor.pos++);
1482 /* now the cursor is at the beginning of the physical par */
1483 SetCursor(cursor.par, cursor.pos + cursor.par->ParFromPos(cursor.pos)->last);
1485 /* the cursor must be exactly before the footnote */
1486 par = cursor.par->ParFromPos(cursor.pos);
1488 status = LyXText::NEED_MORE_REFRESH;
1489 refresh_row = cursor.row;
1490 refresh_y = cursor.y - cursor.row->baseline;
1492 tmppar = cursor.par;
1493 endpar = cursor.par->Next();
1496 tmppar->OpenFootnote(cursor.pos);
1497 RemoveParagraph(row);
1498 /* set the dimensions of the cursor row */
1499 row->fill = Fill(row, paperwidth);
1500 SetHeightOfRow(row);
1501 tmppar = tmppar->Next();
1503 while (tmppar != endpar) {
1505 InsertParagraph(tmppar, row);
1506 while (row->next && row->next->par == tmppar)
1508 tmppar = tmppar->Next();
1511 SetCursor(par->next, 0);
1512 sel_cursor = cursor;
1516 /* table stuff -- begin*/
1518 void LyXText::TableFeatures(int feature, LString val)
1523 if (!cursor.par->table)
1524 return; /* this should never happen */
1526 actCell = NumberOfCell(cursor.par, cursor.pos);
1527 SetUndo(Undo::FINISH,
1528 cursor.par->ParFromPos(cursor.pos)->previous,
1529 cursor.par->ParFromPos(cursor.pos)->next);
1532 case LyXTable::SET_PWIDTH:
1533 cursor.par->table->SetPWidth(actCell,val);
1535 case LyXTable::SET_SPECIAL_COLUMN:
1536 case LyXTable::SET_SPECIAL_MULTI:
1537 cursor.par->table->SetAlignSpecial(actCell,val,feature);
1546 void LyXText::TableFeatures(int feature)
1550 setAlign = LYX_ALIGN_LEFT,
1556 if (!cursor.par->table)
1557 return; /* this should never happen */
1559 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 int pos = cursor.pos;
1580 /* move to the next row */
1581 int cell_org = actCell;
1582 int cell = cell_org;
1584 // if there is a ContRow following this row I have to add
1585 // the row after the ContRow's
1586 if ((pos < cursor.par->Last()) &&
1587 cursor.par->table->RowHasContRow(cell_org)) {
1588 while((pos < cursor.par->Last()) &&
1589 !cursor.par->table->IsContRow(cell)) {
1590 while (pos < cursor.par->Last() &&
1591 !cursor.par->IsNewline(pos))
1593 if (pos < cursor.par->Last())
1597 while((pos < cursor.par->Last()) &&
1598 cursor.par->table->IsContRow(cell)) {
1599 while (pos < cursor.par->Last() &&
1600 !cursor.par->IsNewline(pos))
1602 if (pos < cursor.par->Last())
1607 if (pos < cursor.par->Last())
1610 while (pos < cursor.par->Last() &&
1611 (cell == cell_org || !cursor.par->table->IsFirstCell(cell))){
1612 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1614 if (pos < cursor.par->Last())
1619 /* insert the new cells */
1620 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1622 for (i=0; i<number; i++)
1623 cursor.par->InsertChar(pos, LYX_META_NEWLINE);
1625 /* append the row into the table */
1626 cursor.par->table->AppendRow(cell_org);
1630 case LyXTable::APPEND_CONT_ROW: {
1631 int 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, LYX_META_NEWLINE);
1661 /* append the row into the table */
1662 cursor.par->table->AppendContRow(cell_org);
1666 case LyXTable::APPEND_COLUMN: {
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, LYX_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(), LYX_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->currentBuffer()->the_locking_inset)
1695 UnlockInset(current_view->currentBuffer()->the_locking_inset);
1696 RemoveTableRow(&cursor);
1700 case LyXTable::DELETE_COLUMN: {
1702 int cell_org = actCell;
1704 if (current_view->currentBuffer()->the_locking_inset)
1705 UnlockInset(current_view->currentBuffer()->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);
1737 for (i=sel_start_cursor.pos; i<=sel_end_cursor.pos; i++){
1738 if ((n=NumberOfCell(sel_start_cursor.par,i)) != m) {
1739 cursor.par->table->SetTopLine(n,lineSet);
1747 case LyXTable::TOGGLE_LINE_BOTTOM:
1748 lineSet = !cursor.par->table->BottomLine(actCell);
1750 cursor.par->table->SetBottomLine(actCell,lineSet);
1753 for (i=sel_start_cursor.pos; i<=sel_end_cursor.pos; i++){
1754 if ((n=NumberOfCell(sel_start_cursor.par,i)) != m) {
1755 cursor.par->table->SetBottomLine(n,lineSet);
1763 case LyXTable::TOGGLE_LINE_LEFT:
1764 lineSet = !cursor.par->table->LeftLine(actCell);
1766 cursor.par->table->SetLeftLine(actCell,lineSet);
1769 for (i=sel_start_cursor.pos; i<=sel_end_cursor.pos; i++){
1770 if ((n=NumberOfCell(sel_start_cursor.par,i)) != m) {
1771 cursor.par->table->SetLeftLine(n,lineSet);
1779 case LyXTable::TOGGLE_LINE_RIGHT:
1780 lineSet = !cursor.par->table->RightLine(actCell);
1782 cursor.par->table->SetRightLine(actCell,lineSet);
1785 for (i=sel_start_cursor.pos; i<=sel_end_cursor.pos; i++){
1786 if ((n=NumberOfCell(sel_start_cursor.par,i)) != m) {
1787 cursor.par->table->SetRightLine(n,lineSet);
1795 case LyXTable::ALIGN_LEFT:
1796 case LyXTable::ALIGN_RIGHT:
1797 case LyXTable::ALIGN_CENTER:
1799 cursor.par->table->SetAlignment(actCell,setAlign);
1802 for (i=sel_start_cursor.pos; i<=sel_end_cursor.pos; i++){
1803 if ((n=NumberOfCell(sel_start_cursor.par,i)) != m) {
1804 cursor.par->table->SetAlignment(n,setAlign);
1812 case LyXTable::DELETE_TABLE:
1813 SetCursorIntern(cursor.par, 0);
1814 delete cursor.par->table;
1815 cursor.par->table = NULL;
1816 // temporary: Should put table in simple_cut_buffer (with before and after
1817 // dummy-paragraph !!
1818 // not necessar anymore with UNDO :)
1820 for (i = cursor.par->last-1; i>=0; i--)
1821 cursor.par->Erase(i);
1825 case LyXTable::MULTICOLUMN: {
1827 // check wether we are completly in a multicol
1828 int multicol = cursor.par->table->IsMultiColumn(actCell);
1829 if (multicol && selection && sel_start_cursor.row == sel_end_cursor.row){
1830 multicol = NumberOfCell(sel_start_cursor.par, sel_start_cursor.pos)
1831 == NumberOfCell(sel_end_cursor.par, sel_end_cursor.pos);
1835 int newlines = cursor.par->table->UnsetMultiColumn(actCell);
1836 int pos = cursor.pos;
1837 while (pos<cursor.par->Last() && !cursor.par->IsNewline(pos))
1839 for (;newlines;newlines--)
1840 cursor.par->InsertChar(pos, LYX_META_NEWLINE);
1845 // selection must be in one row (or no selection)
1847 cursor.par->table->SetMultiColumn(NumberOfCell(cursor.par,
1854 if (sel_start_cursor.row == sel_end_cursor.row){
1857 for (i=sel_start_cursor.pos; i<sel_end_cursor.pos; i++){
1858 if (sel_start_cursor.par->IsNewline(i)){
1859 sel_start_cursor.par->Erase(i);
1860 // check for double-blanks
1861 if ((i && !sel_start_cursor.par->IsLineSeparator(i-1))
1863 (i<sel_start_cursor.par->Last()
1864 && !sel_start_cursor.par->IsLineSeparator(i)))
1865 sel_start_cursor.par->InsertChar(i, ' ');
1867 sel_end_cursor.pos--;
1874 SetMultiColumn(NumberOfCell(sel_start_cursor.par,
1875 sel_start_cursor.pos),
1877 cursor.pos = sel_start_cursor.pos;
1882 WriteAlert(_("Impossible Operation!"),
1883 _("Multicolumns can only be horizontally."),
1890 case LyXTable::SET_ALL_LINES:
1892 case LyXTable::UNSET_ALL_LINES:
1894 cursor.par->table->SetAllLines(NumberOfCell(cursor.par,
1899 for (i=sel_start_cursor.pos; i<=sel_end_cursor.pos; i++){
1900 if ((n=NumberOfCell(sel_start_cursor.par,i)) != m) {
1901 cursor.par->table->SetAllLines(n,setLines);
1908 case LyXTable::SET_LONGTABLE:
1909 cursor.par->table->SetLongTable(true);
1911 case LyXTable::UNSET_LONGTABLE:
1912 cursor.par->table->SetLongTable(false);
1914 case LyXTable::SET_ROTATE_TABLE:
1915 cursor.par->table->SetRotateTable(true);
1917 case LyXTable::UNSET_ROTATE_TABLE:
1918 cursor.par->table->SetRotateTable(false);
1920 case LyXTable::SET_ROTATE_CELL:
1922 cursor.par->table->SetRotateCell(actCell,true);
1925 for (i=sel_start_cursor.pos; i<=sel_end_cursor.pos; i++){
1926 if ((n=NumberOfCell(sel_start_cursor.par,i)) != m) {
1927 cursor.par->table->SetRotateCell(n,true);
1933 case LyXTable::UNSET_ROTATE_CELL:
1935 cursor.par->table->SetRotateCell(actCell,false);
1938 for (i=sel_start_cursor.pos; i<=sel_end_cursor.pos; i++){
1939 if ((n=NumberOfCell(sel_start_cursor.par,i)) != m) {
1940 cursor.par->table->SetRotateCell(n,false);
1946 case LyXTable::SET_LINEBREAKS:
1947 what = !cursor.par->table->Linebreaks(cursor.par->table->FirstVirtualCell(actCell));
1949 cursor.par->table->SetLinebreaks(actCell,what);
1952 for (i=sel_start_cursor.pos; i<=sel_end_cursor.pos; i++){
1953 if ((n=NumberOfCell(sel_start_cursor.par,i)) != m) {
1954 cursor.par->table->SetLinebreaks(n,what);
1960 case LyXTable::SET_LTFIRSTHEAD:
1961 cursor.par->table->SetLTHead(actCell,true);
1963 case LyXTable::SET_LTHEAD:
1964 cursor.par->table->SetLTHead(actCell,false);
1966 case LyXTable::SET_LTFOOT:
1967 cursor.par->table->SetLTFoot(actCell,false);
1969 case LyXTable::SET_LTLASTFOOT:
1970 cursor.par->table->SetLTFoot(actCell,true);
1972 case LyXTable::SET_LTNEWPAGE:
1973 what = !cursor.par->table->LTNewPage(actCell);
1974 cursor.par->table->SetLTNewPage(actCell,what);
1980 void LyXText::InsertCharInTable(char c)
1985 bool jumped_over_space;
1987 /* first check, if there will be two blanks together or a blank at
1988 * the beginning of a paragraph.
1989 * I decided to handle blanks like normal characters, the main
1990 * difference are the special checks when calculating the row.fill
1991 * (blank does not count at the end of a row) and the check here */
1993 LyXFont realtmpfont = real_current_font;
1994 LyXFont rawtmpfont = current_font; /* store the current font.
1995 * This is because of the use
1996 * of cursor movements. The moving
1997 * cursor would refresh the
2000 // Get the font that is used to calculate the baselineskip
2001 int const lastpos = cursor.par->Last();
2002 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2004 jumped_over_space = false;
2005 if (IsLineSeparatorChar(c)) {
2007 /* avoid double blanks but insert the new blank because
2008 * of a possible font change */
2009 if (cursor.pos < lastpos &&
2010 cursor.par->IsLineSeparator(cursor.pos))
2012 cursor.par->Erase(cursor.pos);
2013 jumped_over_space = true;
2015 else if ((cursor.pos > 0 &&
2016 cursor.par->IsLineSeparator(cursor.pos - 1))
2017 || (cursor.pos > 0 && cursor.par->IsNewline(cursor.pos - 1))
2018 || (cursor.pos == 0 &&
2019 !(cursor.par->Previous()
2020 && cursor.par->Previous()->footnoteflag
2021 == LyXParagraph::OPEN_FOOTNOTE)))
2024 else if (IsNewlineChar(c)) {
2025 if (!IsEmptyTableCell()) {
2026 TableFeatures(LyXTable::APPEND_CONT_ROW);
2029 /* the newline character is the separator of the cells */
2030 // cursor.par->InsertChar(cursor.pos, c);
2031 // SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2032 // RedoParagraphs(cursor, cursor.par->Next());
2033 // SetCursor(cursor.par, cursor.pos+1);
2038 y = cursor.y - row->baseline;
2039 if (c != LYX_META_INSET) /* in this case LyXText::InsertInset
2040 * already inserted the character */
2041 cursor.par->InsertChar(cursor.pos, c);
2042 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2044 if (!jumped_over_space) {
2045 /* refresh the positions */
2047 while (tmprow->next && tmprow->next->par == row->par) {
2048 tmprow = tmprow->next;
2055 CheckParagraphInTable(cursor.par, cursor.pos);
2057 current_font = rawtmpfont;
2058 real_current_font = realtmpfont;
2060 /* check, whether the last character's font has changed. */
2061 if (cursor.pos && cursor.pos == cursor.par->Last()
2062 && rawparfont != rawtmpfont)
2063 RedoHeightOfParagraph(cursor);
2067 void LyXText::CheckParagraphInTable(LyXParagraph* par, int pos)
2072 if (par->GetChar(pos) == LYX_META_INSET &&
2073 par->GetInset(pos) && par->GetInset(pos)->Display()){
2074 par->GetInset(pos)->SetDisplay(false);
2077 row = GetRow(par, pos, y);
2079 int tmpheight = row->height;
2080 SetHeightOfRow(row);
2083 /* update the table information */
2084 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2086 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2087 WidthOfCell(par, tmp_pos))) {
2088 LyXCursor tmpcursor = cursor;
2089 SetCursorIntern(par, pos);
2090 /* make a complete redraw */
2091 RedoDrawingOfParagraph(cursor);
2095 /* redraw only the row */
2096 LyXCursor tmpcursor = cursor;
2097 SetCursorIntern(par, pos);
2099 refresh_x = cursor.x;
2101 refresh_pos = cursor.pos;
2104 if (tmpheight == row->height)
2105 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2107 status = LyXText::NEED_MORE_REFRESH;
2109 SetCursorIntern(cursor.par, cursor.pos);
2113 void LyXText::BackspaceInTable()
2118 LyXFont rawtmpfont = current_font;
2119 LyXFont realtmpfont = real_current_font;
2121 // Get the font that is used to calculate the baselineskip
2122 int const lastpos = cursor.par->Last();
2123 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2125 if (cursor.pos == 0) {
2126 /* no pasting of table paragraphs */
2131 /* this is the code for a normal backspace, not pasting
2133 SetUndo(Undo::DELETE,
2134 cursor.par->ParFromPos(cursor.pos)->previous,
2135 cursor.par->ParFromPos(cursor.pos)->next);
2139 /* some insets are undeletable here */
2140 if (cursor.par->GetChar(cursor.pos)==LYX_META_INSET) {
2141 if (!cursor.par->GetInset(cursor.pos)->Deletable())
2146 y = cursor.y - row->baseline;
2148 /* some special code when deleting a newline. */
2149 if (cursor.par->IsNewline(cursor.pos)) {
2154 cursor.par->Erase(cursor.pos);
2156 /* refresh the positions */
2158 while (tmprow->next && tmprow->next->par == row->par) {
2159 tmprow = tmprow->next;
2163 /* delete superfluous blanks */
2164 if (cursor.pos < cursor.par->Last() - 1 &&
2165 (cursor.par->IsLineSeparator(cursor.pos))) {
2167 if (cursor.pos == BeginningOfMainBody(cursor.par)
2169 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
2170 cursor.par->Erase(cursor.pos);
2171 /* refresh the positions */
2173 while (tmprow->next &&
2174 tmprow->next->par == row->par) {
2175 tmprow = tmprow->next;
2178 if (cursor.pos) /* move one character left */
2184 CheckParagraphInTable(cursor.par, cursor.pos);
2186 /* check, wether the last characters font has changed. */
2187 if (cursor.pos && cursor.pos == cursor.par->Last()
2188 && rawparfont != rawtmpfont)
2189 RedoHeightOfParagraph(cursor);
2191 /* restore the current font
2192 * That is what a user expects! */
2193 current_font = rawtmpfont;
2194 real_current_font = realtmpfont;
2196 SetCursorIntern(cursor.par, cursor.pos);
2199 /* table stuff -- end*/
2202 /* just a macro to make some thing easier. */
2203 void LyXText::RedoParagraph()
2205 LyXCursor tmpcursor = cursor;
2207 RedoParagraphs(cursor, cursor.par->Next());;
2208 SetCursorIntern(tmpcursor.par, tmpcursor.pos);
2212 /* insert a character, moves all the following breaks in the
2213 * same Paragraph one to the right and make a rebreak */
2214 void LyXText::InsertChar(char c)
2220 bool jumped_over_space;
2221 LyXFont realtmpfont;
2226 SetUndo(Undo::INSERT,
2227 cursor.par->ParFromPos(cursor.pos)->previous,
2228 cursor.par->ParFromPos(cursor.pos)->next);
2230 /* When the free-spacing option is set for the current layout,
2231 * all spaces are converted to protected spaces. */
2232 bool freeSpacingBo =
2233 lyxstyle.Style(parameters->textclass,
2234 cursor.row->par->GetLayout())->free_spacing;
2236 // Is this wanted? There cannot be a line break between protected
2237 // separators. Therefore I suggest the way implemented below
2240 // if ( freeSpacingBo && IsLineSeparatorChar(c) )
2241 // c = LYX_META_PROTECTED_SEPARATOR;
2243 if (freeSpacingBo && IsLineSeparatorChar(c)
2244 && (!cursor.pos || cursor.par->IsLineSeparator(cursor.pos-1)))
2245 c = LYX_META_PROTECTED_SEPARATOR;
2247 /* table stuff -- begin*/
2248 if (cursor.par->table) {
2249 InsertCharInTable(c);
2252 /* table stuff -- end*/
2254 /* first check, if there will be two blanks together or a blank at
2255 * the beginning of a paragraph.
2256 * I decided to handle blanks like normal characters, the main
2257 * difference are the special checks when calculating the row.fill
2258 * (blank does not count at the end of a row) and the check here */
2260 // The bug is triggered when we type in a description environment:
2261 // The current_font is not changed when we go from label to main text
2262 // and it should (along with realtmpfont) when we type the space.
2263 #ifdef WITH_WARNINGS
2264 #warning There is a bug here! (Asger)
2267 realtmpfont = real_current_font;
2268 rawtmpfont = current_font; /* store the current font.
2269 * This is because of the use
2270 * of cursor movements. The moving
2271 * cursor would refresh the
2274 // Get the font that is used to calculate the baselineskip
2275 lastpos = cursor.par->Last();
2276 rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2278 jumped_over_space = false;
2280 if (IsLineSeparatorChar(c)) {
2282 if (cursor.pos < lastpos
2283 && cursor.par->IsLineSeparator(cursor.pos)) {
2284 /* the user inserted a space before a space. So we
2285 * will just make a CursorRight. BUT: The font of this
2286 * space should be set to current font. That is why
2287 * we need to rebreak perhaps. If there is a protected
2288 * blank at the end of a row we have to force
2291 minibuffer->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2292 if (cursor.pos == RowLast(cursor.row)
2293 && !IsLineSeparatorChar(c))
2294 cursor.row->fill = -1; /* force rebreak */
2296 cursor.par->Erase(cursor.pos);
2297 jumped_over_space = true;
2299 } else if ((cursor.pos > 0
2300 && cursor.par->IsLineSeparator(cursor.pos - 1))
2302 && cursor.par->IsNewline(cursor.pos - 1))
2304 && !(cursor.par->Previous()
2305 && cursor.par->Previous()->footnoteflag
2306 == LyXParagraph::OPEN_FOOTNOTE))) {
2307 if (cursor.pos == 0 )
2308 minibuffer->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2310 minibuffer->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2313 } else if (IsNewlineChar(c)) {
2314 if (cursor.par->FirstPhysicalPar() == cursor.par
2315 && cursor.pos <= BeginningOfMainBody(cursor.par))
2317 /* no newline at first position
2318 * of a paragraph or behind labels.
2319 * TeX does not allow that. */
2321 if (cursor.pos < cursor.par->Last() &&
2322 cursor.par->IsLineSeparator(cursor.pos))
2323 CursorRightIntern(); // newline always after a blank!
2324 cursor.row->fill = -1; // to force a new break
2327 /* the display inset stuff */
2328 if (cursor.row->par->GetChar(cursor.row->pos) == LYX_META_INSET
2329 && cursor.row->par->GetInset(cursor.row->pos)
2330 && cursor.row->par->GetInset(cursor.row->pos)->Display())
2331 cursor.row->fill = -1; // to force a new break
2333 /* get the cursor row fist */
2334 /* this is a dumb solution, i will try to hold the cursor.row
2336 /* row = GetRow(cursor.par, cursor.pos, y);*/
2337 /* ok, heres a better way: */
2339 y = cursor.y - row->baseline;
2340 if (c != LYX_META_INSET) /* in this case LyXText::InsertInset
2341 * already insertet the character */
2342 cursor.par->InsertChar(cursor.pos, c);
2343 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2345 if (!jumped_over_space) {
2346 /* refresh the positions */
2348 while (tmprow->next && tmprow->next->par == row->par) {
2349 tmprow = tmprow->next;
2354 /* Is there a break one row above */
2355 if ((cursor.par->IsLineSeparator(cursor.pos)
2356 || cursor.par->IsNewline(cursor.pos)
2357 || cursor.row->fill == -1)
2358 && row->previous && row->previous->par == row->par) {
2359 z = NextBreakPoint(row->previous, paperwidth);
2360 if ( z >= row->pos) {
2363 /* set the dimensions of the row above */
2364 row->previous->fill = Fill(row->previous, paperwidth);
2366 SetHeightOfRow(row->previous);
2368 y -= row->previous->height;
2370 refresh_row = row->previous;
2371 status = LyXText::NEED_MORE_REFRESH;
2373 BreakAgainOneRow(row);
2374 SetCursor(cursor.par, cursor.pos + 1);
2375 /* cursor MUST be in row now */
2377 if (row->next && row->next->par == row->par)
2378 need_break_row = row->next;
2380 need_break_row = NULL;
2382 current_font = rawtmpfont;
2383 real_current_font = realtmpfont;
2385 // check, wether the last characters font has changed.
2386 if (cursor.pos && cursor.pos == cursor.par->Last()
2387 && rawparfont != rawtmpfont)
2388 RedoHeightOfParagraph(cursor);
2394 /* recalculate the fill of the row */
2395 if (row->fill >= 0) /* needed because a newline
2396 * will set fill to -1. Otherwise
2397 * we would not get a rebreak! */
2398 row->fill = Fill(row, paperwidth);
2399 if (row->fill < 0 ) {
2402 refresh_x = cursor.x;
2403 refresh_pos = cursor.pos;
2404 status = LyXText::NEED_MORE_REFRESH;
2405 BreakAgainOneRow(row);
2406 /* will the cursor be in another row now? */
2407 if (RowLast(row) <= cursor.pos + 1 && row->next) {
2408 if (row->next && row->next->par == row->par)
2412 BreakAgainOneRow(row);
2414 SetCursor(cursor.par, cursor.pos + 1);
2415 if (row->next && row->next->par == row->par)
2416 need_break_row = row->next;
2418 need_break_row = NULL;
2420 current_font = rawtmpfont;
2421 real_current_font = realtmpfont;
2424 refresh_x = cursor.x;
2426 refresh_pos = cursor.pos;
2428 int tmpheight = row->height;
2429 SetHeightOfRow(row);
2430 if (tmpheight == row->height)
2431 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2433 status = LyXText::NEED_MORE_REFRESH;
2435 SetCursor(cursor.par, cursor.pos + 1);
2436 current_font = rawtmpfont;
2437 real_current_font = realtmpfont;
2440 /* check, wether the last characters font has changed. */
2441 if (cursor.pos && cursor.pos == cursor.par->Last()
2442 && rawparfont != rawtmpfont) {
2443 RedoHeightOfParagraph(cursor);
2445 /* now the special right address boxes */
2446 if (lyxstyle.Style(parameters->textclass,
2447 cursor.par->GetLayout())->margintype
2448 == MARGIN_RIGHT_ADDRESS_BOX) {
2449 RedoDrawingOfParagraph(cursor);
2454 // Here we could call FinishUndo for every 20 characters inserted.
2455 // This is from my experience how emacs does it.
2456 static unsigned short counter = 0;
2467 void LyXText::PrepareToPrint(Row *row, float &x, float &fill_separator,
2468 float &fill_hfill, float &fill_label_hfill)
2470 float w, nh, nlh, ns;
2474 fill_label_hfill = 0;
2476 fill_label_hfill = 0;
2478 x = LeftMargin(row);
2480 /* is there a manual margin with a manual label */
2481 if (lyxstyle.Style(parameters->textclass,
2482 row->par->GetLayout())->margintype == MARGIN_MANUAL
2483 && lyxstyle.Style(parameters->textclass,
2484 row->par->GetLayout())->labeltype == LABEL_MANUAL) {
2486 nlh = NumberOfLabelHfills(row) + 1; /* one more since labels
2487 * are left aligned*/
2488 if (nlh && !row->par->GetLabelWidthString().empty()) {
2489 fill_label_hfill = LabelFill(row) / nlh;
2493 /* are there any hfills in the row? */
2494 nh = NumberOfHfills(row);
2496 /* table stuff -- begin*/
2497 if (row->par->table) {
2498 w = paperwidth - row->par->table->WidthOfTable()
2499 - x - RightMargin(row);
2500 nh = 0; /* ignore hfills in tables */
2502 /* table stuff -- end*/
2507 /* is it block, flushleft or flushright?
2508 * set x how you need it */
2510 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2511 align = lyxstyle.Style(parameters->textclass, row->par->GetLayout())->align;
2513 align = row->par->FirstPhysicalPar()->align;
2515 /* center displayed insets */
2516 if (row->par->GetChar(row->pos) == LYX_META_INSET
2517 && row->par->GetInset(row->pos)
2518 && row->par->GetInset(row->pos)->Display())
2519 align = LYX_ALIGN_CENTER;
2522 case LYX_ALIGN_BLOCK:
2523 ns = NumberOfSeparators(row);
2524 if (ns && row->next && row->next->par == row->par &&
2525 !(row->next->par->IsNewline(row->next->pos-1))
2526 && !(row->next->par->GetChar(row->next->pos) == LYX_META_INSET
2527 && row->next->par->GetInset(row->next->pos)
2528 && row->next->par->GetInset(row->next->pos)->Display())
2530 fill_separator = w / ns;
2532 case LYX_ALIGN_RIGHT:
2535 case LYX_ALIGN_CENTER:
2543 /* important for the screen */
2546 /* the cursor set functions have a special mechanism. When they
2547 * realize, that you left an empty paragraph, they will delete it.
2548 * They also delete the corresponding row */
2550 void LyXText::CursorRightOneWord()
2552 // treat floats, HFills and Insets as words
2553 LyXCursor tmpcursor = cursor;
2555 if (tmpcursor.pos == tmpcursor.par->Last()
2556 && tmpcursor.par->Next())
2558 tmpcursor.par = tmpcursor.par->Next();
2563 // Skip through initial nonword stuff.
2564 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2565 ! tmpcursor.par->IsWord( tmpcursor.pos ) )
2567 // printf("Current pos1 %d",tmpcursor.pos) ;
2571 // Advance through word.
2572 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2573 tmpcursor.par->IsWord( tmpcursor.pos ) )
2575 // printf("Current pos2 %d",tmpcursor.pos) ;
2580 SetCursor(tmpcursor.par, tmpcursor.pos);
2584 void LyXText::CursorTab()
2586 if (cursor.par->table) {
2587 int cell = NumberOfCell(cursor.par, cursor.pos);
2588 while(cursor.par->table->IsContRow(cell)) {
2590 cell = NumberOfCell(cursor.par, cursor.pos);
2592 if (cursor.par->table->ShouldBeVeryLastCell(cell))
2593 TableFeatures(LyXTable::APPEND_ROW);
2595 LyXCursor tmpcursor = cursor;
2596 while (tmpcursor.pos < tmpcursor.par->Last()
2597 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2600 if (tmpcursor.pos == tmpcursor.par->Last()){
2601 if (tmpcursor.par->Next()) {
2602 tmpcursor.par = tmpcursor.par->Next();
2608 SetCursor(tmpcursor.par, tmpcursor.pos);
2609 if (cursor.par->table) {
2610 int cell = NumberOfCell(cursor.par, cursor.pos);
2611 while (cursor.par->table->IsContRow(cell) &&
2612 !cursor.par->table->ShouldBeVeryLastCell(cell)) {
2614 while (tmpcursor.pos < tmpcursor.par->Last()
2615 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2618 if (tmpcursor.pos == tmpcursor.par->Last()){
2619 if (tmpcursor.par->Next()) {
2620 tmpcursor.par = tmpcursor.par->Next();
2626 SetCursor(tmpcursor.par, tmpcursor.pos);
2627 cell = NumberOfCell(cursor.par, cursor.pos);
2633 /* -------> Skip initial whitespace at end of word and move cursor to *start*
2634 of prior word, not to end of next prior word. */
2636 void LyXText::CursorLeftOneWord()
2638 // treat HFills, floats and Insets as words
2639 LyXCursor tmpcursor = cursor;
2640 while (tmpcursor.pos
2641 && (tmpcursor.par->IsSeparator(tmpcursor.pos - 1)
2642 || tmpcursor.par->IsKomma(tmpcursor.pos - 1))
2643 && !(tmpcursor.par->IsHfill(tmpcursor.pos - 1)
2644 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2645 || tmpcursor.par->IsInset(tmpcursor.pos - 1)))
2649 && (tmpcursor.par->IsInset(tmpcursor.pos - 1)
2650 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2651 || tmpcursor.par->IsHfill(tmpcursor.pos - 1))) {
2653 } else if (!tmpcursor.pos) {
2654 if (tmpcursor.par->Previous()){
2655 tmpcursor.par = tmpcursor.par->Previous();
2656 tmpcursor.pos = tmpcursor.par->Last();
2658 } else { // Here, tmpcursor != 0
2659 while (tmpcursor.pos > 0 &&
2660 tmpcursor.par->IsWord(tmpcursor.pos-1) )
2663 SetCursor(tmpcursor.par, tmpcursor.pos);
2666 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
2669 void LyXText::SelectWord()
2671 /* Move cursor to the beginning, when not already there. */
2673 && !cursor.par->IsSeparator(cursor.pos-1)
2674 && !cursor.par->IsKomma(cursor.pos-1) )
2675 CursorLeftOneWord();
2677 /* set the sel cursor */
2678 sel_cursor = cursor;
2680 while ( cursor.pos < cursor.par->Last()
2681 && !cursor.par->IsSeparator(cursor.pos)
2682 && !cursor.par->IsKomma(cursor.pos) )
2684 SetCursor( cursor.par, cursor.pos );
2686 /* finally set the selection */
2691 /* -------> Select the word currently under the cursor when:
2692 1: no selection is currently set,
2693 2: the cursor is not at the borders of the word. */
2695 int LyXText::SelectWordWhenUnderCursor()
2697 if ( selection ) return 0;
2698 if ( cursor.pos < cursor.par->Last()
2699 && !cursor.par->IsSeparator(cursor.pos)
2700 && !cursor.par->IsKomma(cursor.pos)
2702 && !cursor.par->IsSeparator(cursor.pos -1)
2703 && !cursor.par->IsKomma(cursor.pos -1) ) {
2711 // This function is only used by the spellchecker for NextWord().
2712 // It doesn't handle LYX_ACCENTs and probably never will.
2713 char* LyXText::SelectNextWord(float &value)
2715 LyXParagraph* tmppar = cursor.par;
2717 // If this is not the very first word, skip rest of
2718 // current word because we are probably in the middle
2719 // of a word if there is text here.
2720 if (cursor.pos || cursor.par->previous) {
2721 while (cursor.pos < cursor.par->Last()
2722 && cursor.par->IsLetter(cursor.pos))
2725 // Now, skip until we have real text (will jump paragraphs)
2726 while ((cursor.par->Last() > cursor.pos
2727 && (!cursor.par->IsLetter(cursor.pos)
2728 || cursor.par->getFont(cursor.pos).latex() == LyXFont::ON))
2729 || (cursor.par->Last() == cursor.pos
2730 && cursor.par->Next())){
2731 if (cursor.pos == cursor.par->Last()) {
2732 cursor.par = cursor.par->Next();
2739 // Update the value if we changed paragraphs
2740 if (cursor.par != tmppar){
2741 SetCursor(cursor.par, cursor.pos);
2742 value = float(cursor.y)/float(height);
2745 /* Start the selection from here */
2746 sel_cursor = cursor;
2750 /* and find the end of the word
2751 (optional hyphens are part of a word) */
2752 while (cursor.pos < cursor.par->Last()
2753 && (cursor.par->IsLetter(cursor.pos))
2754 || (cursor.par->GetChar(cursor.pos) == LYX_META_INSET &&
2755 cursor.par->GetInset(cursor.pos) != 0 &&
2756 cursor.par->GetInset(cursor.pos)->Latex(latex,0)==0 &&
2760 // Finally, we copy the word to a string and return it
2761 char* string = NULL;
2763 if (sel_cursor.pos < cursor.pos) {
2764 string = new char [cursor.pos - sel_cursor.pos + 2];
2767 for (i=sel_cursor.pos, j=0; i<cursor.pos; i++) {
2768 if (cursor.par->GetChar(i) != LYX_META_INSET)
2769 string[j++] = cursor.par->GetChar(i);
2777 // This one is also only for the spellchecker
2778 void LyXText::SelectSelectedWord()
2780 /* move cursor to the beginning */
2781 SetCursor(sel_cursor.par, sel_cursor.pos);
2783 /* set the sel cursor */
2784 sel_cursor = cursor;
2788 /* now find the end of the word */
2789 while (cursor.pos < cursor.par->Last()
2790 && (cursor.par->IsLetter(cursor.pos)
2791 || (cursor.par->GetChar(cursor.pos) == LYX_META_INSET &&
2792 cursor.par->GetInset(cursor.pos) != 0 &&
2793 cursor.par->GetInset(cursor.pos)->Latex(latex,0)==0 &&
2797 SetCursor(cursor.par, cursor.pos);
2799 /* finally set the selection */
2804 /* -------> Delete from cursor up to the end of the current or next word. */
2805 void LyXText::DeleteWordForward()
2807 LyXCursor tmpcursor = cursor;
2809 if (!cursor.par->Last())
2812 /* -------> Skip initial non-word stuff. */
2813 while ( cursor.pos < cursor.par->Last()
2814 && (cursor.par->IsSeparator(cursor.pos)
2815 || cursor.par->IsKomma(cursor.pos)) )
2818 SetCursorIntern(cursor.par, cursor.pos);
2819 selection = True; // to avoid deletion
2820 CursorRightOneWord();
2821 sel_cursor = cursor;
2825 /* -----> Great, CutSelection() gets rid of multiple spaces. */
2831 /* -------> Delete from cursor to start of current or prior word. */
2832 void LyXText::DeleteWordBackward()
2834 LyXCursor tmpcursor = cursor;
2835 if (!cursor.par->Last())
2838 selection = True; // to avoid deletion
2839 CursorLeftOneWord();
2840 sel_cursor = cursor;
2848 /* -------> Kill to end of line. */
2849 void LyXText::DeleteLineForward()
2851 LyXCursor tmpcursor = cursor;
2852 if (!cursor.par->Last())
2856 sel_cursor = cursor;
2859 if (selection == false) {
2860 DeleteWordForward();
2867 // Change the case of a word at cursor position. The meaning of action
2869 // 0 change to lowercase
2870 // 1 capitalize word
2871 // 2 change to uppercase
2872 // This function directly manipulates LyXParagraph::text because there
2873 // is no LyXParagraph::SetChar currently. I did what I could to ensure
2874 // that it is correct. I guess part of it should be moved to
2875 // LyXParagraph, but it will have to change for 1.1 anyway. At least
2876 // it does not access outside of the allocated array as the older
2877 // version did. (JMarc)
2878 void LyXText::ChangeWordCase(int action)
2880 LyXParagraph *tmppar = cursor.par->ParFromPos(cursor.pos);
2881 int tmppos = cursor.par->PositionInParFromPos(cursor.pos);
2883 SetUndo(Undo::FINISH, tmppar->previous, tmppar->next);
2885 while (tmppos < tmppar->last) {
2886 unsigned char c = tmppar->text[tmppos];
2887 if (IsKommaChar(c) || IsLineSeparatorChar(c))
2889 if (c != LYX_META_INSET) {
2904 tmppar->text[tmppos] = c;
2907 CheckParagraph(tmppar, tmppos);
2908 CursorRightOneWord();
2912 void LyXText::Delete()
2914 LyXCursor old_cursor = cursor;
2915 LyXCursor tmpcursor;
2916 /* this is a very easy implementation*/
2918 /* just move to the right */
2919 CursorRightIntern();
2921 if (cursor.par->previous == old_cursor.par->previous
2922 && cursor.par != old_cursor.par)
2923 return; // delete-emty-paragraph-mechanism has done it
2925 /* if you had success make a backspace */
2926 if (old_cursor.par != cursor.par || old_cursor.pos != cursor.pos) {
2928 cursor = old_cursor; // to make sure undo gets the right cursor position
2929 SetUndo(Undo::DELETE,
2930 cursor.par->ParFromPos(cursor.pos)->previous,
2931 cursor.par->ParFromPos(cursor.pos)->next);
2938 void LyXText::Backspace()
2940 LyXParagraph *tmppar;
2945 /* table stuff -- begin*/
2947 if (cursor.par->table) {
2951 /* table stuff -- end*/
2953 LyXFont rawtmpfont = current_font;
2954 LyXFont realtmpfont = real_current_font;
2956 // Get the font that is used to calculate the baselineskip
2957 int const lastpos = cursor.par->Last();
2958 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2960 if (cursor.pos == 0) {
2961 /* we may paste some paragraphs */
2963 /* is it an empty paragraph? */
2966 || (lastpos == 1 && cursor.par->IsSeparator(0)))
2967 && !(cursor.par->Next()
2968 && cursor.par->footnoteflag ==
2969 LyXParagraph::NO_FOOTNOTE
2970 && cursor.par->Next()->footnoteflag ==
2971 LyXParagraph::OPEN_FOOTNOTE)) {
2973 if (cursor.par->previous) {
2974 tmppar = cursor.par->previous->FirstPhysicalPar();
2975 if (cursor.par->GetLayout() == tmppar->GetLayout()
2976 && cursor.par->footnoteflag == tmppar->footnoteflag
2977 && cursor.par->GetAlign() == tmppar->GetAlign()) {
2979 tmppar->line_bottom = cursor.par->line_bottom;
2980 tmppar->added_space_bottom = cursor.par->added_space_bottom;
2981 tmppar->pagebreak_bottom = cursor.par->pagebreak_bottom;
2986 /* the layout things can change the height of a row ! */
2987 tmpheight = cursor.row->height;
2988 SetHeightOfRow(cursor.row);
2989 if (cursor.row->height != tmpheight) {
2990 refresh_y = cursor.y - cursor.row->baseline;
2991 refresh_row = cursor.row;
2992 status = LyXText::NEED_MORE_REFRESH;
2997 if (cursor.par->ParFromPos(cursor.pos)->previous){
2998 SetUndo(Undo::DELETE,
2999 cursor.par->ParFromPos(cursor.pos)->previous->previous,
3000 cursor.par->ParFromPos(cursor.pos)->next);
3002 tmppar = cursor.par;
3003 tmprow = cursor.row;
3005 /* Pasting is not allowed, if the paragraphs have different layout.
3006 * I think it is a real bug of all other word processors to allow
3007 * it. It confuses the user. Even so with a footnote paragraph and
3008 * a non-footnote paragraph. I will not allow pasting in this case,
3009 * because the user would be confused if the footnote behaves
3010 * different wether it is open or closed.
3012 * Correction: Pasting is always allowed with standard-layout */
3013 if (cursor.par != tmppar
3014 && (cursor.par->GetLayout() == tmppar->GetLayout()
3015 || !tmppar->GetLayout())
3016 && cursor.par->footnoteflag == tmppar->footnoteflag
3017 /* table stuff -- begin*/
3018 && !cursor.par->table /* no pasting of tables */
3019 /* table stuff -- end*/
3020 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3022 cursor.par->PasteParagraph();
3025 cursor.par->IsSeparator(cursor.pos - 1)))
3026 cursor.par->InsertChar(cursor.pos, ' ');
3031 status = LyXText::NEED_MORE_REFRESH;
3032 refresh_row = cursor.row;
3033 refresh_y = cursor.y - cursor.row->baseline;
3035 /* remove the lost paragraph */
3036 RemoveParagraph(tmprow);
3039 /* break the paragraph again */
3040 /* BreakAgain(cursor.row); */
3042 AppendParagraph(cursor.row);
3043 UpdateCounters(cursor.row);
3045 /* the row may have changed, block, hfills etc. */
3046 SetCursor(cursor.par, cursor.pos);
3049 /* this is the code for a normal backspace, not pasting
3051 SetUndo(Undo::DELETE,
3052 cursor.par->ParFromPos(cursor.pos)->previous,
3053 cursor.par->ParFromPos(cursor.pos)->next);
3056 /* some insets are undeletable here */
3057 if (cursor.par->GetChar(cursor.pos)==LYX_META_INSET) {
3058 if (!cursor.par->GetInset(cursor.pos)->Deletable())
3060 /* force complete redo when erasing display insets */
3061 /* this is a cruel mathod but save..... Matthias */
3062 if (cursor.par->GetInset(cursor.pos)->Display()){
3063 cursor.par->Erase(cursor.pos);
3070 y = cursor.y - row->baseline;
3073 /* remember that a space at the end of a row doesnt count
3074 * when calculating the fill */
3075 if (cursor.pos < RowLast(row) ||
3076 !cursor.par->IsLineSeparator(cursor.pos)) {
3077 row->fill += SingleWidth(cursor.par, cursor.pos);
3080 /* some special code when deleting a newline. This is similar
3081 * to the behavior when pasting paragraphs */
3082 if (cursor.pos && cursor.par->IsNewline(cursor.pos)) {
3083 cursor.par->Erase(cursor.pos);
3084 /* refresh the positions */
3086 while (tmprow->next && tmprow->next->par == row->par) {
3087 tmprow = tmprow->next;
3090 if (cursor.par->IsLineSeparator(cursor.pos - 1))
3093 if (cursor.pos < cursor.par->Last() && !cursor.par->IsSeparator(cursor.pos)) {
3094 cursor.par->InsertChar(cursor.pos, ' ');
3095 /* refresh the positions */
3097 while (tmprow->next && tmprow->next->par == row->par) {
3098 tmprow = tmprow->next;
3103 cursor.par->Erase(cursor.pos);
3105 /* refresh the positions */
3107 while (tmprow->next && tmprow->next->par == row->par) {
3108 tmprow = tmprow->next;
3112 /* delete superfluous blanks */
3113 if (cursor.pos < cursor.par->Last() - 1 &&
3114 (cursor.par->IsLineSeparator(cursor.pos))) {
3116 if (cursor.pos == BeginningOfMainBody(cursor.par)
3118 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
3119 cursor.par->Erase(cursor.pos);
3120 /* refresh the positions */
3122 while (tmprow->next &&
3123 tmprow->next->par == row->par) {
3124 tmprow = tmprow->next;
3127 if (cursor.pos) /* move one character left */
3132 /* delete newlines at the beginning of paragraphs */
3133 while (cursor.par->Last() &&
3134 cursor.par->IsNewline(cursor.pos) &&
3135 cursor.pos == BeginningOfMainBody(cursor.par)
3137 cursor.par->Erase(cursor.pos);
3138 /* refresh the positions */
3140 while (tmprow->next &&
3141 tmprow->next->par == row->par) {
3142 tmprow = tmprow->next;
3148 /* is there a break one row above */
3149 if (row->previous && row->previous->par == row->par) {
3150 z = NextBreakPoint(row->previous, paperwidth);
3151 if ( z >= row->pos) {
3154 tmprow = row->previous;
3156 /* maybe the current row is now empty */
3157 if (row->pos >= row->par->Last()) {
3160 need_break_row = NULL;
3163 BreakAgainOneRow(row);
3164 if (row->next && row->next->par == row->par)
3165 need_break_row = row->next;
3167 need_break_row = NULL;
3170 /* set the dimensions of the row above */
3171 y -= tmprow->height;
3172 tmprow->fill = Fill(tmprow, paperwidth);
3173 SetHeightOfRow(tmprow);
3176 refresh_row = tmprow;
3177 status = LyXText::NEED_MORE_REFRESH;
3178 SetCursor(cursor.par, cursor.pos);
3179 current_font = rawtmpfont;
3180 real_current_font = realtmpfont;
3181 /* check, whether the last character's font has changed. */
3182 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3183 if (rawparfont != rawtmpfont)
3184 RedoHeightOfParagraph(cursor);
3189 /* break the cursor row again */
3190 z = NextBreakPoint(row, paperwidth);
3192 if ( z != RowLast(row) ||
3193 (row->next && row->next->par == row->par &&
3194 RowLast(row) == row->par->Last() - 1)){
3196 /* it can happen that a paragraph loses one row
3197 * without a real breakup. This is when a word
3198 * is to long to be broken. Well, I don t care this
3200 if (row->next && row->next->par == row->par &&
3201 RowLast(row) == row->par->Last() - 1)
3202 RemoveRow(row->next);
3206 status = LyXText::NEED_MORE_REFRESH;
3208 BreakAgainOneRow(row);
3210 SetCursor(cursor.par, cursor.pos);
3211 /* cursor MUST be in row now */
3213 if (row->next && row->next->par == row->par)
3214 need_break_row = row->next;
3216 need_break_row = NULL;
3218 /* set the dimensions of the row */
3219 row->fill = Fill(row, paperwidth);
3220 int tmpheight = row->height;
3221 SetHeightOfRow(row);
3222 if (tmpheight == row->height)
3223 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3225 status = LyXText::NEED_MORE_REFRESH;
3228 SetCursor(cursor.par, cursor.pos);
3232 /* restore the current font
3233 * That is what a user expects! */
3234 current_font = rawtmpfont;
3235 real_current_font = realtmpfont;
3237 /* check, wether the last characters font has changed. */
3238 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3239 if (rawparfont != rawtmpfont) {
3240 RedoHeightOfParagraph(cursor);
3242 /* now the special right address boxes */
3243 if (lyxstyle.Style(parameters->textclass,
3244 cursor.par->GetLayout())->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3245 RedoDrawingOfParagraph(cursor);
3251 void LyXText::GetVisibleRow(LyXScreen &scr, int offset,
3252 Row *row_ptr, long y)
3254 /* returns a printed row */
3258 int y_top, y_bottom;
3259 float fill_separator, fill_hfill, fill_label_hfill;
3260 LyXParagraph *par, *firstpar;
3264 if (row_ptr->height <= 0) {
3265 fprintf(stderr, "LYX_ERROR: row.height: %d \n",
3269 left_margin = LabelEnd(row_ptr);
3270 PrepareToPrint(row_ptr, x, fill_separator,
3271 fill_hfill, fill_label_hfill);
3273 int main_body = BeginningOfMainBody(row_ptr->par);
3275 /* initialize the pixmap */
3277 scr.fillRectangle(gc_clear,
3278 0, offset, paperwidth, row_ptr->height);
3279 // check for NOT FAST SELECTION
3280 if (!fast_selection && !mono_video && selection) {
3281 /* selection code */
3282 if (sel_start_cursor.row == row_ptr &&
3283 sel_end_cursor.row == row_ptr) {
3284 scr.fillRectangle(gc_selection, sel_start_cursor.x,
3290 else if (sel_start_cursor.row == row_ptr) {
3291 scr.fillRectangle(gc_selection, sel_start_cursor.x,
3293 paperwidth - sel_start_cursor.x,
3295 } else if (sel_end_cursor.row == row_ptr) {
3296 scr.fillRectangle(gc_selection,0, offset,
3297 sel_end_cursor.x, row_ptr->height);
3298 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
3299 scr.fillRectangle(gc_selection, 0, offset,
3300 paperwidth, row_ptr->height);
3303 } // end of NOT FAST SELECTION code
3305 if (row_ptr->par->appendix){
3306 scr.drawVerticalLine(gc_math, 1, offset, offset+row_ptr->height);
3307 scr.drawVerticalLine(gc_math, paperwidth-2 , offset, offset+row_ptr->height);
3310 if (row_ptr->par->pextra_type == PEXTRA_MINIPAGE) {
3311 /* draw a marker at the left margin! */
3312 LyXFont font = GetFont(row_ptr->par, 0);
3313 int asc = font.maxAscent();
3314 int x = (LYX_PAPER_MARGIN - font.width('|')) / 2;
3315 int y1 = (offset + row_ptr->baseline);
3316 int y2 = (offset + row_ptr->baseline) - asc;
3318 scr.drawVerticalLine(gc_minipage, x, y1, y2);
3320 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3321 LyXFont font(LyXFont::ALL_SANE);
3322 font.setSize(LyXFont::SIZE_FOOTNOTE);
3323 font.setColor(LyXFont::RED);
3325 int box_x = LYX_PAPER_MARGIN;
3326 box_x += font.textWidth(" wide-tab ", 10);
3327 if (row_ptr->previous &&
3328 row_ptr->previous->par->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3330 switch (row_ptr->par->footnotekind) {
3331 case LyXParagraph::MARGIN:
3334 case LyXParagraph::FIG:
3337 case LyXParagraph::TAB:
3340 case LyXParagraph::WIDE_FIG:
3343 case LyXParagraph::WIDE_TAB:
3346 case LyXParagraph::ALGORITHM:
3349 case LyXParagraph::FOOTNOTE:
3354 // Determine background color.
3355 gc_type back = gc_lighted;
3359 scr.fillRectangle(back,LYX_PAPER_MARGIN, offset+1,
3360 box_x - LYX_PAPER_MARGIN,
3361 int(font.maxAscent())+
3362 int(font.maxDescent()));
3364 scr.drawLine(gc_foot,
3367 paperwidth - 2*LYX_PAPER_MARGIN);
3369 scr.drawString(font, fs,
3370 offset + int(font.maxAscent())+1,
3372 scr.drawVerticalLine(gc_foot,
3376 + int(font.maxAscent())+
3377 int(font.maxDescent()));
3379 scr.drawLine(gc_foot,
3381 + int(font.maxAscent())
3382 + int(font.maxDescent()) + 1,
3383 LYX_PAPER_MARGIN, box_x - LYX_PAPER_MARGIN);
3386 /* draw the open floats in a red box */
3387 scr.drawVerticalLine(gc_foot,
3389 offset, offset + row_ptr->height);
3391 scr.drawVerticalLine(gc_foot,
3392 paperwidth - LYX_PAPER_MARGIN,
3394 offset + row_ptr->height);
3398 if (row_ptr->previous &&
3399 row_ptr->previous->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3400 LyXFont font(LyXFont::ALL_SANE);
3401 font.setSize(LyXFont::SIZE_FOOTNOTE);
3403 int box_x = LYX_PAPER_MARGIN;
3404 box_x += font.textWidth(" wide-tab ", 10);
3406 scr.drawLine(gc_foot,
3409 paperwidth - LYX_PAPER_MARGIN - box_x);
3413 LyXLayout* layout = lyxstyle.Style(parameters->textclass,
3414 row_ptr->par->GetLayout());
3415 firstpar = row_ptr->par->FirstPhysicalPar();
3418 y_bottom = row_ptr->height;
3420 /* is it a first row? */
3421 if (row_ptr->pos == 0
3422 && row_ptr->par == firstpar) {
3424 /* start of appendix? */
3425 if (row_ptr->par->start_of_appendix){
3426 scr.drawLine(gc_math,
3431 /* think about the margins */
3432 if (!row_ptr->previous)
3433 y_top += LYX_PAPER_MARGIN;
3435 if (row_ptr->par->pagebreak_top){ /* draw a top pagebreak */
3436 scr.drawOnOffLine(offset + y_top + 2 * DefaultHeight(),
3438 y_top += 3 * DefaultHeight();
3441 if (row_ptr->par->added_space_top.kind() == VSpace::VFILL) {
3442 /* draw a vfill top */
3443 scr.drawLine(gc_fill,
3445 0, LYX_PAPER_MARGIN);
3446 scr.drawLine(gc_fill,
3447 offset + y_top + 3 * DefaultHeight(),
3448 0, LYX_PAPER_MARGIN);
3449 scr.drawVerticalOnOffLine(LYX_PAPER_MARGIN / 2,
3451 offset + y_top + 3 *
3454 y_top += 3 * DefaultHeight();
3457 /* think about user added space */
3458 y_top += int(row_ptr->par->added_space_top.inPixels());
3460 /* think about the parskip */
3461 /* some parskips VERY EASY IMPLEMENTATION */
3462 if (parameters->paragraph_separation == LYX_PARSEP_SKIP) {
3463 if (layout->latextype == LATEX_PARAGRAPH
3464 && firstpar->GetDepth() == 0
3465 && firstpar->Previous())
3466 y_top += parameters->getDefSkip().inPixels();
3467 else if (firstpar->Previous()
3468 && lyxstyle.Style(parameters->textclass,
3469 firstpar->Previous()->GetLayout())->latextype == LATEX_PARAGRAPH
3470 && firstpar->Previous()->GetDepth() == 0)
3471 // is it right to use defskip here, too? (AS)
3472 y_top += parameters->getDefSkip().inPixels();
3475 if (row_ptr->par->line_top) { /* draw a top line */
3476 y_top += GetFont(row_ptr->par, 0).ascent('x');
3478 scr.drawThickLine(offset + y_top,
3480 y_top += GetFont(row_ptr->par, 0).ascent('x');
3483 /* should we print a label? */
3484 if (layout->labeltype >= LABEL_STATIC
3485 && (layout->labeltype != LABEL_STATIC
3486 || layout->latextype != LATEX_ENVIRONMENT
3487 || row_ptr->par->IsFirstInSequence())) {
3488 font = GetFont(row_ptr->par, -2);
3489 if (!row_ptr->par->GetLabelString().empty()) {
3491 LString tmpstring = row_ptr->par->GetLabelString();
3493 if (layout->labeltype == LABEL_COUNTER_CHAPTER) {
3494 if (parameters->secnumdepth >=0){
3495 /* this is special code for the chapter layout. This is printed in
3496 * an extra row and has a pagebreak at the top. */
3497 maxdesc = int(font.maxDescent() * layout->spacing.getValue() * parameters->spacing.getValue())
3498 + int(layout->parsep) * DefaultHeight();
3499 scr.drawString(font, tmpstring,
3500 offset + row_ptr->baseline
3501 - row_ptr->ascent_of_text - maxdesc,
3505 x -= font.stringWidth( layout->labelsep);
3506 x -= font.stringWidth( tmpstring);
3508 scr.drawString(font, tmpstring,
3509 offset + row_ptr->baseline, int(x));
3513 /* the labels at the top of an environment. More or less for bibliography */
3514 } else if (layout->labeltype == LABEL_TOP_ENVIRONMENT ||
3515 layout->labeltype == LABEL_BIBLIO ||
3516 layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
3517 if (row_ptr->par->IsFirstInSequence()) {
3518 font = GetFont(row_ptr->par, -2);
3519 if (!row_ptr->par->GetLabelString().empty()) {
3520 LString tmpstring = row_ptr->par->GetLabelString();
3522 maxdesc = int(font.maxDescent() * layout->spacing.getValue() * parameters->spacing.getValue()
3523 + (layout->labelbottomsep * DefaultHeight()));
3525 int top_label_x = int(x);
3526 if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
3527 top_label_x = int(x + (paperwidth - RightMargin(row_ptr) - x) / 2);
3528 top_label_x -= (font.stringWidth( tmpstring)/2);
3531 scr.drawString(font, tmpstring,
3532 offset + row_ptr->baseline
3533 - row_ptr->ascent_of_text - maxdesc,
3538 if (layout->labeltype==LABEL_BIBLIO) { // ale970302
3539 if (row_ptr->par->bibkey) {
3541 x -= font.stringWidth(layout->labelsep);
3542 font = GetFont(row_ptr->par, -1);
3543 x -= row_ptr->par->bibkey->Width(font);
3544 row_ptr->par->bibkey->Draw(font, scr,
3545 offset + row_ptr->baseline,
3552 /* is it a last row? */
3553 par = row_ptr->par->LastPhysicalPar();
3554 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
3555 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
3557 /* think about the margins */
3559 y_bottom -= LYX_PAPER_MARGIN;
3561 /* draw a bottom pagebreak */
3562 if (firstpar->pagebreak_bottom) {
3563 scr.drawOnOffLine(offset + y_bottom - 2 *
3566 y_bottom -= 3 * DefaultHeight();
3569 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
3570 /* draw a vfill bottom */
3571 scr.drawLine(gc_fill,
3572 offset + y_bottom - 3 * DefaultHeight(),
3573 0, LYX_PAPER_MARGIN);
3574 scr.drawLine(gc_fill, offset + y_bottom - 2,
3575 0, LYX_PAPER_MARGIN);
3576 scr.drawVerticalOnOffLine(LYX_PAPER_MARGIN / 2,
3577 offset + y_bottom - 3 * DefaultHeight(),
3578 offset + y_bottom - 2
3580 y_bottom -= 3* DefaultHeight();
3583 /* think about user added space */
3584 y_bottom -= int(firstpar->added_space_bottom.inPixels());
3586 if (firstpar->line_bottom) {
3587 /* draw a bottom line */
3588 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3590 scr.drawThickLine(offset + y_bottom,
3592 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3596 /* draw the text in the pixmap */
3597 pos_end = RowLast(row_ptr);
3600 /* table stuff -- begin*/
3601 if (row_ptr->par->table) {
3603 int cell = NumberOfCell(row_ptr->par, row_ptr->pos);
3605 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3607 while (pos <= pos_end) {
3608 if (row_ptr->par->IsNewline(pos)) {
3610 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
3611 /* draw the table lines, still very simple */
3612 on_off = !row_ptr->par->table->TopLine(cell);
3614 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
3615 !row_ptr->par->table->IsContRow(cell))
3616 scr.drawTableLine(offset + row_ptr->baseline -
3617 row_ptr->ascent_of_text,
3618 int(x_old), int(x - x_old), on_off);
3619 on_off = !row_ptr->par->table->BottomLine(cell);
3620 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
3621 row_ptr->par->table->VeryLastRow(cell))
3622 scr.drawTableLine(offset + y_bottom - 1,
3623 int(x_old), int(x - x_old), on_off);
3624 on_off = !row_ptr->par->table->LeftLine(cell);
3626 scr.drawVerticalTableLine(int(x_old),
3627 offset + row_ptr->baseline -
3628 row_ptr->ascent_of_text,
3629 offset + y_bottom - 1,
3631 on_off = !row_ptr->par->table->RightLine(cell);
3633 scr.drawVerticalTableLine(int(x) -
3634 row_ptr->par->table->AdditionalWidth(cell),
3635 offset + row_ptr->baseline -
3636 row_ptr->ascent_of_text,
3637 offset + y_bottom - 1,
3640 /* take care about the alignment and other spaces */
3642 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3643 if (row_ptr->par->table->IsFirstCell(cell))
3644 cell--; // little hack, sorry
3646 } else if (row_ptr->par->IsHfill(pos)) {
3649 scr.drawVerticalLine(gc_fill, int(x),
3650 offset + row_ptr->baseline - DefaultHeight()/2,
3651 offset + row_ptr->baseline);
3655 if (row_ptr->par->IsSeparator(pos)) {
3657 x+=SingleWidth(row_ptr->par, pos);
3658 /* -------> Only draw protected spaces when not in
3659 * free-spacing mode. */
3660 if (row_ptr->par->GetChar(pos)==LYX_META_PROTECTED_SEPARATOR && !layout->free_spacing) {
3661 scr.drawVerticalLine(gc_fill, int(tmpx),
3662 offset + row_ptr->baseline - 3,
3663 offset + row_ptr->baseline - 1);
3664 scr.drawLine(gc_fill,
3665 offset + row_ptr->baseline - 1,
3668 scr.drawVerticalLine(gc_fill, int(x-2),
3669 offset + row_ptr->baseline - 3,
3670 offset + row_ptr->baseline - 1);
3671 /* what about underbars? */
3672 font = GetFont(row_ptr->par, pos);
3673 if (font.underbar() == LyXFont::ON
3674 && font.latex() != LyXFont::ON) {
3675 scr.drawLine(gc_copy,
3677 row_ptr->baseline + 2,
3684 Draw(row_ptr, pos, scr, offset, x);
3688 /* do not forget the very last cell. This has no NEWLINE so
3689 * ignored by the code above*/
3690 if (cell == row_ptr->par->table->GetNumberOfCells()-1){
3691 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
3692 on_off = !row_ptr->par->table->TopLine(cell);
3694 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
3695 !row_ptr->par->table->IsContRow(cell))
3697 scr.drawTableLine(offset + row_ptr->baseline -
3698 row_ptr->ascent_of_text,
3699 int(x_old), int(x - x_old), on_off);
3700 on_off = !row_ptr->par->table->BottomLine(cell);
3701 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
3702 row_ptr->par->table->VeryLastRow(cell))
3704 scr.drawTableLine(offset + y_bottom - 1,
3705 int(x_old), int(x - x_old), on_off);
3706 on_off = !row_ptr->par->table->LeftLine(cell);
3708 scr.drawVerticalTableLine(int(x_old),
3709 offset + row_ptr->baseline -
3710 row_ptr->ascent_of_text,
3711 offset + y_bottom - 1,
3713 on_off = !row_ptr->par->table->RightLine(cell);
3715 scr.drawVerticalTableLine(int(x) -
3716 row_ptr->par->table->AdditionalWidth(cell),
3717 offset + row_ptr->baseline -
3718 row_ptr->ascent_of_text,
3719 offset + y_bottom - 1,
3723 /* table stuff -- end*/
3725 while (pos <= pos_end) {
3727 if (row_ptr->par->IsHfill(pos)) {
3729 scr.drawVerticalLine(gc_fill, int(x),
3730 offset + row_ptr->baseline - DefaultHeight()/2,
3731 offset + row_ptr->baseline);
3732 if (HfillExpansion(row_ptr,pos)) {
3733 if (pos >= main_body) {
3734 scr.drawOnOffLine(offset + row_ptr->baseline -
3740 scr.drawOnOffLine(offset + row_ptr->baseline -
3743 int(fill_label_hfill));
3744 x += fill_label_hfill;
3746 scr.drawVerticalLine(gc_fill, int(x),
3747 offset + row_ptr->baseline -
3749 offset + row_ptr->baseline);
3754 if (row_ptr->par->IsSeparator(pos)) {
3756 x+=SingleWidth(row_ptr->par, pos);
3757 if (pos >= main_body)
3759 /* -------> Only draw protected spaces when not in
3760 * free-spacing mode. */
3761 if (row_ptr->par->GetChar(pos)==LYX_META_PROTECTED_SEPARATOR && !layout->free_spacing) {
3763 scr.drawVerticalLine(gc_fill, int(tmpx),
3764 offset + row_ptr->baseline - 3,
3765 offset + row_ptr->baseline - 1);
3766 scr.drawLine(gc_fill,
3767 offset + row_ptr->baseline - 1,
3770 scr.drawVerticalLine(gc_fill, int(x-2),
3771 offset + row_ptr->baseline - 3,
3772 offset + row_ptr->baseline - 1);
3773 /* what about underbars? */
3774 font = GetFont(row_ptr->par, pos);
3775 if (font.underbar() == LyXFont::ON
3776 && font.latex() != LyXFont::ON) {
3777 scr.drawLine(gc_copy,
3778 offset + row_ptr->baseline + 2,
3785 Draw(row_ptr, pos, scr, offset, x);
3787 if (pos == main_body) {
3788 x += GetFont(row_ptr->par, -2).stringWidth(
3790 if (row_ptr->par->IsLineSeparator(pos - 1))
3791 x-= SingleWidth(row_ptr->par, pos - 1);
3792 if (x < left_margin)
3797 // check for FAST SELECTION
3798 if (fast_selection || mono_video){
3801 /* selection code */
3802 if (sel_start_cursor.row == row_ptr && sel_end_cursor.row == row_ptr) {
3803 scr.fillRectangle(gc_select,sel_start_cursor.x, offset,
3804 sel_end_cursor.x - sel_start_cursor.x,
3806 } else if (sel_start_cursor.row == row_ptr) {
3807 scr.fillRectangle(gc_select, sel_start_cursor.x, offset,
3808 paperwidth - sel_start_cursor.x,
3810 } else if (sel_end_cursor.row == row_ptr) {
3811 scr.fillRectangle(gc_select, 0, offset,
3814 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
3815 scr.fillRectangle(gc_select, 0, offset,
3816 paperwidth, row_ptr->height);
3821 // end of FAST SELECTION code
3826 int LyXText::DefaultHeight()
3828 LyXFont font(LyXFont::ALL_SANE);
3829 return int(font.maxAscent() + font.maxDescent() * 1.5);
3833 /* returns the column near the specified x-coordinate of the row
3834 * x is set to the real beginning of this column */
3835 int LyXText::GetColumnNearX(Row *row, int& x)
3839 float fill_separator, fill_hfill, fill_label_hfill;
3842 left_margin = LabelEnd(row);
3843 PrepareToPrint(row, tmpx, fill_separator,
3844 fill_hfill, fill_label_hfill);
3845 int main_body = BeginningOfMainBody(row->par);
3849 int last = RowLast(row);
3850 if (row->par->IsNewline(last))
3853 LyXLayout *layout = lyxstyle.Style(parameters->textclass,
3854 row->par->GetLayout());
3855 /* table stuff -- begin*/
3856 if (row->par->table) {
3857 if (!row->next || row->next->par != row->par)
3858 last = RowLast(row); /* the last row doesn't need a newline at the end*/
3859 int cell = NumberOfCell(row->par, row->pos);
3862 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
3864 && tmpx + (SingleWidth(row->par, c)/2) <= x
3866 if (row->par->IsNewline(c)) {
3867 if (x_old + row->par->table->WidthOfColumn(cell) <= x){
3868 tmpx = x_old + row->par->table->WidthOfColumn(cell);
3871 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
3876 tmpx += SingleWidth(row->par, c);
3881 /* table stuff -- end*/
3884 && tmpx + (SingleWidth(row->par, c)/2) <= x) {
3886 if (c && c == main_body
3887 && !row->par->IsLineSeparator(c - 1)) {
3888 tmpx += GetFont(row->par, -2)
3889 .stringWidth(layout->labelsep);
3890 if (tmpx < left_margin)
3894 tmpx += SingleWidth(row->par, c);
3895 if (HfillExpansion(row, c)) {
3899 tmpx += fill_label_hfill;
3901 else if (c >= main_body
3902 && row->par->IsSeparator(c)) {
3903 tmpx+= fill_separator;
3907 && row->par->IsLineSeparator(c - 1)) {
3908 tmpx += GetFont(row->par, -2)
3909 .stringWidth(layout->labelsep);
3910 tmpx-= SingleWidth(row->par, c - 1);
3911 if (tmpx < left_margin)
3915 /* make sure that a last space in a row doesnt count */
3916 if (c > 0 && c >= last
3917 && row->par->IsLineSeparator(c - 1)
3918 && !(!row->next || row->next->par != row->par)) {
3919 tmpx -= SingleWidth(row->par, c - 1);
3920 tmpx -= fill_separator;
3929 /* turn the selection into a new environment. If there is no selection,
3930 * create an empty environment */
3931 void LyXText::InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind)
3933 /* no footnoteenvironment in a footnoteenvironment */
3934 if (cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3935 WriteAlert(_("Impossible operation"),
3936 _("You can't insert a float in a float!"),
3940 /* no marginpars in minipages */
3941 if (kind == LyXParagraph::MARGIN
3942 && cursor.par->pextra_type == PEXTRA_MINIPAGE) {
3943 WriteAlert(_("Impossible operation"),
3944 _("You can't insert a marginpar in a minipage!"),
3949 /* this doesnt make sense, if there is no selection */
3950 bool dummy_selection = false;
3952 sel_start_cursor = cursor; /* dummy selection */
3953 sel_end_cursor = cursor;
3954 dummy_selection = true;
3957 LyXParagraph *tmppar;
3959 if (sel_start_cursor.par->table || sel_end_cursor.par->table){
3960 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
3964 /* a test to make sure there is not already a footnote
3965 * in the selection. */
3967 tmppar = sel_start_cursor.par->ParFromPos(sel_start_cursor.pos);
3969 while (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos) &&
3970 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
3971 tmppar = tmppar->next;
3973 if (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)
3974 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3975 WriteAlert(_("Impossible operation"),
3976 _("Float would include float!"),
3981 /* ok we have a selection. This is always between sel_start_cursor
3982 * and sel_end cursor */
3984 SetUndo(Undo::FINISH,
3985 sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous,
3986 sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)->next);
3988 if (sel_end_cursor.pos > 0
3989 && sel_end_cursor.par->IsLineSeparator(sel_end_cursor.pos - 1))
3990 sel_end_cursor.pos--; /* please break before a space at
3992 if (sel_start_cursor.par == sel_end_cursor.par
3993 && sel_start_cursor.pos > sel_end_cursor.pos)
3994 sel_start_cursor.pos--;
3996 sel_end_cursor.par->BreakParagraphConservative(sel_end_cursor.pos);
3998 sel_end_cursor.par = sel_end_cursor.par->Next();
3999 sel_end_cursor.pos = 0;
4001 // don't forget to insert a dummy layout paragraph if necessary
4002 if (sel_start_cursor.par->GetLayout() != sel_end_cursor.par->layout){
4003 sel_end_cursor.par->BreakParagraphConservative(0);
4004 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4005 sel_end_cursor.par = sel_end_cursor.par->next;
4008 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4010 cursor = sel_end_cursor;
4012 /* please break behind a space, if there is one. The space should
4014 if (sel_start_cursor.pos > 0
4015 && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1))
4016 sel_start_cursor.pos--;
4017 if (sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) {
4018 sel_start_cursor.par->Erase(sel_start_cursor.pos);
4021 sel_start_cursor.par->BreakParagraphConservative(sel_start_cursor.pos);
4022 tmppar = sel_start_cursor.par->Next();
4024 if (dummy_selection) {
4026 if (kind == LyXParagraph::TAB
4027 || kind == LyXParagraph::FIG
4028 || kind == LyXParagraph::WIDE_TAB
4029 || kind == LyXParagraph::WIDE_FIG
4030 || kind == LyXParagraph::ALGORITHM) {
4031 int lay = lyxstyle.NumberOfLayout(parameters->textclass,
4033 if (lay == -1) // layout not found
4034 // use default layout "Standard" (0)
4036 tmppar->SetLayout(lay);
4040 if (sel_start_cursor.pos > 0) {
4041 /* the footnote-environment should begin with a standard layout.
4042 * Imagine you insert a footnote within an enumeration, you
4043 * certainly do not want an enumerated footnote! */
4047 /* this is a exception the user would sometimes expect, I hope */
4048 sel_start_cursor.par->Clear();
4052 while (tmppar != sel_end_cursor.par) {
4053 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4054 tmppar->footnotekind = kind;
4055 tmppar = tmppar->Next();
4058 RedoParagraphs(sel_start_cursor, sel_end_cursor.par->Next());
4060 SetCursor(sel_start_cursor.par->Next(), 0);
4066 /* returns pointer to a specified row */
4067 Row* LyXText::GetRow(LyXParagraph *par, int pos, long &y)
4072 if (par == currentrow->par || par == currentrow->par->Previous()){
4073 // do not dereference par, it may have been deleted
4074 // already! (Matthias)
4075 while (currentrow->previous && currentrow->previous->par != par){
4076 currentrow = currentrow->previous;
4077 currentrow_y -= currentrow->height;
4079 while (currentrow->previous && currentrow->previous->par == par){
4080 currentrow = currentrow->previous;
4081 currentrow_y -= currentrow->height;
4084 tmprow = currentrow;
4086 /* find the first row of the specified paragraph */
4087 while (tmprow->next && (tmprow->par != par)) {
4088 y += tmprow->height;
4089 tmprow = tmprow->next;
4092 if (tmprow->par == par){
4093 /* now find the wanted row */
4094 while (tmprow->pos < pos && tmprow->next && tmprow->next->par == par &&
4095 tmprow->next->pos <= pos) {
4096 y += tmprow->height;
4097 tmprow = tmprow->next;
4099 currentrow = tmprow;
4106 /* find the first row of the specified paragraph */
4107 while (tmprow->next && (tmprow->par != par)) {
4108 y += tmprow->height;
4109 tmprow = tmprow->next;
4112 /* now find the wanted row */
4113 while (tmprow->pos < pos && tmprow->next && tmprow->next->par == par &&
4114 tmprow->next->pos <= pos) {
4115 y += tmprow->height;
4116 tmprow = tmprow->next;
4119 currentrow = tmprow;