1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * ====================================================== */
16 #pragma implementation "table.h"
20 #include "lyxparagraph.h"
22 #include "support/textutils.h"
23 #include "lyx_gui_misc.h"
25 #include "bufferparams.h"
27 #include "minibuffer.h"
37 static const int LYX_PAPER_MARGIN = 20;
39 extern BufferView * current_view;
43 extern int bibitemMaxWidth(Painter &, LyXFont const &);
45 #define FIX_DOUBLE_SPACE 1
47 int LyXText::SingleWidth(LyXParagraph * par,
48 LyXParagraph::size_type pos) const
50 char c = par->GetChar(pos);
51 return SingleWidth(par, pos, c);
55 int LyXText::SingleWidth(LyXParagraph * par,
56 LyXParagraph::size_type pos, char c) const
58 LyXFont font = GetFont(par, pos);
60 // The most common case is handled first (Asger)
64 } else if (IsHfillChar(c)) {
65 return 3; /* Because of the representation
66 * as vertical lines */
67 } else if (c == LyXParagraph::META_FOOTNOTE ||
68 c == LyXParagraph::META_MARGIN ||
69 c == LyXParagraph::META_FIG ||
70 c == LyXParagraph::META_TAB ||
71 c == LyXParagraph::META_WIDE_FIG ||
72 c == LyXParagraph::META_WIDE_TAB ||
73 c == LyXParagraph::META_ALGORITHM) {
76 case LyXParagraph::META_MARGIN:
79 case LyXParagraph::META_FIG:
82 case LyXParagraph::META_TAB:
85 case LyXParagraph::META_ALGORITHM:
88 case LyXParagraph::META_WIDE_FIG:
91 case LyXParagraph::META_WIDE_TAB:
94 case LyXParagraph::META_FOOTNOTE:
100 return font.stringWidth(fs);
101 } else if (c == LyXParagraph::META_INSET) {
102 Inset * tmpinset= par->GetInset(pos);
104 return par->GetInset(pos)->width(owner_->painter(),
109 } else if (IsSeparatorChar(c))
111 else if (IsNewlineChar(c))
113 return font.width(c);
117 // Returns the paragraph position of the last character in the specified row
118 LyXParagraph::size_type LyXText::RowLast(Row const * row) const
121 return row->par->Last() - 1;
122 else if (row->next->par != row->par)
123 return row->par->Last() - 1;
125 return row->next->pos - 1;
129 LyXDirection BufferParams::getDocumentDirection() const
131 return (lyxrc->rtl_support && language == "hebrew")
132 ? LYX_DIR_RIGHT_TO_LEFT : LYX_DIR_LEFT_TO_RIGHT;
135 LyXDirection LyXParagraph::getParDirection() const
137 if (!lyxrc->rtl_support || table)
138 return LYX_DIR_LEFT_TO_RIGHT;
141 return (getFont(0).direction() == LyXFont::RTL_DIR)
142 ? LYX_DIR_RIGHT_TO_LEFT : LYX_DIR_LEFT_TO_RIGHT;
144 return current_view->buffer()->params.getDocumentDirection();
147 LyXDirection LyXFont::getFontDirection() const
149 if (lyxrc->rtl_support
150 && direction() == LyXFont::RTL_DIR
151 && latex() != LyXFont::ON)
152 return LYX_DIR_RIGHT_TO_LEFT;
154 return LYX_DIR_LEFT_TO_RIGHT;
158 LyXParagraph::getLetterDirection(LyXParagraph::size_type pos) const
160 if (!lyxrc->rtl_support)
161 return LYX_DIR_LEFT_TO_RIGHT;
163 LyXDirection direction = getFont(pos).getFontDirection();
164 if (IsLineSeparator(pos) && 0 < pos && pos < Last() - 1
165 && !IsLineSeparator(pos + 1)
166 && !(table && IsNewline(pos + 1))
167 && (getFont(pos - 1).getFontDirection() != direction
168 || getFont(pos + 1).getFontDirection() != direction))
169 return getParDirection();
175 void LyXText::ComputeBidiTables(Row * row) const
178 if (!lyxrc->rtl_support) {
182 LyXParagraph::size_type last = RowLast(row);
183 bidi_start = row->pos;
185 if (bidi_start > last) {
190 if (last + 2 - bidi_start >
191 static_cast<LyXParagraph::size_type>(log2vis_list.size())) {
192 LyXParagraph::size_type new_size =
193 (last + 2 - bidi_start < 500) ?
194 500 : 2 * (last + 2 - bidi_start);
195 log2vis_list.resize(new_size);
196 vis2log_list.resize(new_size);
199 vis2log_list[last + 1 - bidi_start] = -1;
200 log2vis_list[last + 1 - bidi_start] = -1;
202 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
203 if (main_body > 0 && row->pos < main_body - 1 && main_body - 1 <= last
204 && row->par->IsLineSeparator(main_body - 1)) {
205 // This is needed in case there is a direction change in
206 // the label which is continued into the main body
207 if (row->par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) {
208 ComputeBidiTablesFromTo(row, bidi_start,
210 log2vis_list[main_body - 1 - bidi_start] =
212 vis2log_list[main_body - 1 - bidi_start] =
214 if (main_body <= last)
215 ComputeBidiTablesFromTo(row,
218 ComputeBidiTablesFromTo(row, bidi_start,
220 last - main_body + 2);
221 log2vis_list[main_body - 1 - bidi_start] =
222 last - main_body + 1 + bidi_start;
223 vis2log_list[last - main_body + 1 - bidi_start] =
225 if (main_body <= last)
226 ComputeBidiTablesFromTo(row, main_body,
230 ComputeBidiTablesFromTo(row, bidi_start, last, 0);
234 void LyXText::ComputeBidiTablesFromTo(Row * row,
235 LyXParagraph::size_type from,
236 LyXParagraph::size_type to,
237 LyXParagraph::size_type offset) const
239 LyXParagraph::size_type vpos, old_lpos, stack[2];
240 LyXDirection par_direction = row->par->getParDirection();
241 LyXDirection direction = par_direction;
242 LyXParagraph::size_type lpos = from;
246 if (row->par->getLetterDirection(lpos) == direction) {
247 log2vis_list[lpos - bidi_start] = direction;
251 (level == 1 && direction == LYX_DIR_RIGHT_TO_LEFT
252 && row->par->getFont(lpos).direction() ==
254 && row->par->getFont(lpos).latex() ==
256 // The last check is needed when the
258 stack[level++] = lpos;
260 old_lpos = stack[--level];
261 log2vis_list[old_lpos - bidi_start] =
262 log2vis_list[lpos - bidi_start] =
263 (old_lpos - lpos) * direction;
266 direction = static_cast<LyXDirection>(-direction);
271 old_lpos = stack[--level];
272 log2vis_list[old_lpos - bidi_start] =
273 (old_lpos - (to + 1)) * direction;
274 direction = static_cast<LyXDirection>(-direction);
277 vpos = (par_direction == LYX_DIR_LEFT_TO_RIGHT)
280 for (lpos = from; lpos <= to; ++lpos) {
281 vpos += log2vis_list[lpos - bidi_start];
282 vis2log_list[vpos - bidi_start] = lpos;
283 log2vis_list[lpos - bidi_start] = vpos;
288 void LyXText::draw(Row const * row,
289 LyXParagraph::size_type & vpos,
290 int offset, float & x)
292 Painter & pain = owner_->painter();
294 LyXParagraph::size_type pos = vis2log(vpos);
295 char c = row->par->GetChar(pos);
297 if (IsNewlineChar(c)) {
299 // Draw end-of-line marker
300 LyXFont font = GetFont(row->par, pos);
301 int wid = font.width('n');
302 int asc = font.maxAscent();
303 int y = offset + row->baseline;
306 if (row->par->getLetterDirection(pos) == LYX_DIR_LEFT_TO_RIGHT) {
307 xp[0] = int(x + wid * 0.375);
308 yp[0] = int(y - 0.875 * asc * 0.75);
311 yp[1] = int(y - 0.500 * asc * 0.75);
313 xp[2] = int(x + wid * 0.375);
314 yp[2] = int(y - 0.125 * asc * 0.75);
316 pain.lines(xp, yp, 3, LColor::eolmarker);
319 yp[0] = int(y - 0.500 * asc * 0.75);
321 xp[1] = int(x + wid);
322 yp[1] = int(y - 0.500 * asc * 0.75);
324 xp[2] = int(x + wid);
325 yp[2] = int(y - asc * 0.75);
327 pain.lines(xp, yp, 3, LColor::eolmarker);
329 xp[0] = int(x + wid * 0.625);
330 yp[0] = int(y - 0.875 * asc * 0.75);
332 xp[1] = int(x + wid);
333 yp[1] = int(y - 0.500 * asc * 0.75);
335 xp[2] = int(x + wid * 0.625);
336 yp[2] = int(y - 0.125 * asc * 0.75);
338 pain.lines(xp, yp, 3, LColor::eolmarker);
340 xp[0] = int(x + wid);
341 yp[0] = int(y - 0.500 * asc * 0.75);
344 yp[1] = int(y - 0.500 * asc * 0.75);
347 yp[2] = int(y - asc * 0.75);
349 pain.lines(xp, yp, 3, LColor::eolmarker);
355 LyXFont font = GetFont(row->par, pos);
356 LyXFont font2 = font;
358 if (c == LyXParagraph::META_FOOTNOTE
359 || c == LyXParagraph::META_MARGIN
360 || c == LyXParagraph::META_FIG
361 || c == LyXParagraph::META_TAB
362 || c == LyXParagraph::META_WIDE_FIG
363 || c == LyXParagraph::META_WIDE_TAB
364 || c == LyXParagraph::META_ALGORITHM) {
367 case LyXParagraph::META_MARGIN:
369 // Draw a sign at the left margin!
371 .text((LYX_PAPER_MARGIN - font.width('!'))/2,
372 offset + row->baseline, "!", 1, font);
374 case LyXParagraph::META_FIG:
377 case LyXParagraph::META_TAB:
380 case LyXParagraph::META_ALGORITHM:
383 case LyXParagraph::META_WIDE_FIG:
386 case LyXParagraph::META_WIDE_TAB:
389 case LyXParagraph::META_FOOTNOTE:
396 // calculate the position of the footnotemark
397 int y = (row->baseline - font2.maxAscent()
400 font.setColor(LColor::footnote);
404 // draw it and set new x position
406 pain.text(int(x), offset + y, fs, font);
407 x += pain.width(fs, font);
408 pain.line(int(tmpx), offset + row->baseline,
409 int(x), offset + row->baseline,
414 } else if (c == LyXParagraph::META_INSET) {
415 Inset * tmpinset = row->par->GetInset(pos);
417 tmpinset->draw(owner_->painter(), font,
418 offset + row->baseline, x);
423 /* usual characters, no insets */
425 // Collect character that we can draw in one command
427 // This is dirty, but fast. Notice that it will never be too small.
428 // For the record, I'll note that Microsoft Word has a limit
429 // of 768 here. We have none :-) (Asger)
430 // Ok. I am the first to admit that the use of std::string will be
431 // a tiny bit slower than using a POD char array. However, I claim
432 // that this slowdown is so small that it is close to inperceptive.
433 // So IMHO we should go with the easier and clearer implementation.
434 // And even if 1024 is a large number here it might overflow, string
435 // will only overflow if the machine is out of memory...
436 static string textstring;
440 LyXParagraph::size_type last = RowLast(row);
442 while (vpos <= last &&
443 (pos = vis2log(vpos)) >= 0
444 && static_cast<unsigned char>(c = row->par->GetChar(pos)) > ' '
445 && font2 == GetFont(row->par, pos)) {
451 // Draw text and set the new x position
452 pain.text(int(x), offset + row->baseline, textstring, font);
453 x += pain.width(textstring, font);
455 // what about underbars?
456 if (font.underbar() == LyXFont::ON && font.latex() != LyXFont::ON) {
457 pain.line(tmpx, offset + row->baseline + 2,
458 x, offset + row->baseline + 2);
462 // If we want ulem.sty support, drawing
463 // routines should go here. (Asger)
464 // Why shouldn't LyXFont::drawText handle it internally?
468 // Returns the left beginning of the text.
469 // This information cannot be taken from the layouts-objekt, because in
470 // LaTeX the beginning of the text fits in some cases (for example sections)
471 // exactly the label-width.
472 int LyXText::LeftMargin(Row const * row) const
474 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
475 row->par->GetLayout());
477 string parindent = layout.parindent;
479 /* table stuff -- begin */
482 /* table stuff -- end */
484 int x = LYX_PAPER_MARGIN;
486 x += textclasslist.TextClass(parameters->textclass)
488 .signedStringWidth(textclasslist
489 .TextClass(parameters->textclass)
492 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
493 LyXFont font(LyXFont::ALL_SANE);
494 font.setSize(LyXFont::SIZE_SMALL);
495 x += font.textWidth("Mwide-figM", 10) + LYX_PAPER_MARGIN/2;
498 // this is the way, LyX handles the LaTeX-Environments.
499 // I have had this idea very late, so it seems to be a
500 // later added hack and this is true
501 if (!row->par->GetDepth()) {
502 if (!row->par->GetLayout()) {
503 // find the previous same level paragraph
504 if (row->par->FirstPhysicalPar()->Previous()) {
505 LyXParagraph * newpar = row->par
506 ->DepthHook(row->par->GetDepth());
508 textclasslist.Style(parameters->textclass,
515 // find the next level paragraph
517 LyXParagraph * newpar = row->par->DepthHook(row->par->GetDepth()-1);
519 // make a corresponding row. Needed to call LeftMargin()
521 // check wether it is a sufficent paragraph
522 if (newpar && newpar->footnoteflag == row->par->footnoteflag
524 .Style(parameters->textclass,
525 newpar->GetLayout()).isEnvironment()) {
527 dummyrow.par = newpar;
528 dummyrow.pos = newpar->Last();
529 x = LeftMargin(&dummyrow);
531 // this is no longer an error, because this function
532 // is used to clear impossible depths after changing
533 // a layout. Since there is always a redo,
534 // LeftMargin() is always called
535 row->par->FirstPhysicalPar()->depth = 0;
538 if (newpar && !row->par->GetLayout()) {
539 if (newpar->FirstPhysicalPar()->noindent)
542 parindent = textclasslist
543 .Style(parameters->textclass,
544 newpar->GetLayout()).parindent;
549 LyXFont labelfont = GetFont(row->par, -2);
550 switch (layout.margintype) {
552 if (!layout.leftmargin.empty()) {
554 .TextClass(parameters->textclass)
556 .signedStringWidth(layout.leftmargin);
558 if (!row->par->GetLabestring().empty()) {
559 x += labelfont.signedStringWidth(layout.labelindent);
560 x += labelfont.stringWidth(row->par->GetLabestring());
561 x += labelfont.stringWidth(layout.labelsep);
565 x += labelfont.signedStringWidth(layout.labelindent);
566 if (row->pos >= BeginningOfMainBody(row->par)) {
567 if (!row->par->GetLabelWidthString().empty()) {
569 .stringWidth(row->par
570 ->GetLabelWidthString());
571 x += labelfont.stringWidth(layout.labelsep);
576 x += textclasslist.TextClass(parameters->textclass)
577 .defaultfont().signedStringWidth(layout.leftmargin) * 4
578 / (row->par->GetDepth() + 4);
580 case MARGIN_FIRST_DYNAMIC:
581 if (layout.labeltype == LABEL_MANUAL) {
582 if (row->pos >= BeginningOfMainBody(row->par)) {
584 .signedStringWidth(layout.leftmargin);
587 .signedStringWidth(layout.labelindent);
590 // Special case to fix problems with
592 || (layout.labeltype == LABEL_STATIC
593 && layout.latextype == LATEX_ENVIRONMENT
594 && ! row->par->IsFirstInSequence())) {
595 x += labelfont.signedStringWidth(layout.leftmargin);
596 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
597 && layout.labeltype != LABEL_BIBLIO
598 && layout.labeltype !=
599 LABEL_CENTERED_TOP_ENVIRONMENT) {
600 x += labelfont.signedStringWidth(layout.labelindent);
601 x += labelfont.stringWidth(layout.labelsep);
602 x += labelfont.stringWidth(row->par->GetLabestring());
606 case MARGIN_RIGHT_ADDRESS_BOX:
608 // ok, a terrible hack. The left margin depends on the widest
609 // row in this paragraph. Do not care about footnotes, they
610 // are *NOT* allowed in the LaTeX realisation of this layout.
612 // find the first row of this paragraph
613 Row const * tmprow = row;
614 while (tmprow->previous && tmprow->previous->par == row->par)
615 tmprow = tmprow->previous;
617 int minfill = tmprow->fill;
618 while (tmprow->next && tmprow->next->par == row->par) {
619 tmprow = tmprow->next;
620 if (tmprow->fill < minfill)
621 minfill = tmprow->fill;
624 x += textclasslist.TextClass(parameters->textclass)
625 .defaultfont().signedStringWidth(layout.leftmargin);
630 if (row->par->pextra_type == LyXParagraph::PEXTRA_INDENT) {
631 if (!row->par->pextra_widthp.empty()) {
633 atoi(row->par->pextra_widthp.c_str()) / 100;
634 } else if (!row->par->pextra_width.empty()) {
635 int xx = VSpace(row->par->pextra_width).inPixels();
638 xx = paperwidth * 80 / 100;
640 } else { // should not happen
641 LyXFont font(LyXFont::ALL_SANE);
642 x += font.stringWidth("XXXXXX");
647 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
648 align = layout.align;
650 align = row->par->FirstPhysicalPar()->align;
652 // set the correct parindent
654 if ((layout.labeltype == LABEL_NO_LABEL
655 || layout.labeltype == LABEL_TOP_ENVIRONMENT
656 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
657 || (layout.labeltype == LABEL_STATIC
658 && layout.latextype == LATEX_ENVIRONMENT
659 && ! row->par->IsFirstInSequence()))
660 && row->par == row->par->FirstPhysicalPar()
661 && align == LYX_ALIGN_BLOCK
662 && !row->par->noindent
663 && (row->par->layout ||
664 parameters->paragraph_separation ==
665 BufferParams::PARSEP_INDENT))
666 x += textclasslist.TextClass(parameters->textclass)
667 .defaultfont().signedStringWidth(parindent);
668 else if (layout.labeltype == LABEL_BIBLIO) {
669 // ale970405 Right width for bibitems
670 x += bibitemMaxWidth(owner_->painter(),
672 .TextClass(parameters
681 int LyXText::RightMargin(Row const * row) const
683 LyXLayout const & layout =
684 textclasslist.Style(parameters->textclass,
685 row->par->GetLayout());
687 int x = LYX_PAPER_MARGIN
689 .TextClass(parameters->textclass)
691 .signedStringWidth(textclasslist
692 .TextClass(parameters->textclass)
695 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
696 x += LYX_PAPER_MARGIN / 2;
699 // this is the way, LyX handles the LaTeX-Environments.
700 // I have had this idea very late, so it seems to be a
701 // later added hack and this is true
702 if (row->par->GetDepth()) {
703 // find the next level paragraph
705 LyXParagraph * newpar = row->par;
708 newpar = newpar->FirstPhysicalPar()->Previous();
710 newpar = newpar->FirstPhysicalPar();
711 } while (newpar && newpar->GetDepth() >= row->par->GetDepth()
712 && newpar->footnoteflag == row->par->footnoteflag);
714 // make a corresponding row. Needed to call LeftMargin()
716 // check wether it is a sufficent paragraph
717 if (newpar && newpar->footnoteflag == row->par->footnoteflag
718 && textclasslist.Style(parameters->textclass,
722 dummyrow.par = newpar;
724 x = RightMargin(&dummyrow);
726 // this is no longer an error, because this function
727 // is used to clear impossible depths after changing
728 // a layout. Since there is always a redo,
729 // LeftMargin() is always called
730 row->par->FirstPhysicalPar()->depth = 0;
734 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
735 x += textclasslist.TextClass(parameters->textclass)
737 .signedStringWidth(layout.rightmargin) * 4
738 / (row->par->GetDepth() + 4);
743 int LyXText::LabelEnd (Row const * row) const
745 if (textclasslist.Style(parameters->textclass,
746 row->par->GetLayout()).margintype
750 tmprow.pos = row->par->Last();
751 return LeftMargin(&tmprow); /* just the beginning
754 return 0; /* LabelEnd is only needed, if the
755 layout fills a flushleft
760 /* table stuff -- begin*/
761 int LyXText::NumberOfCell(LyXParagraph * par,
762 LyXParagraph::size_type pos) const
765 LyXParagraph::size_type tmp_pos = 0;
766 while (tmp_pos < pos) {
767 if (par->IsNewline(tmp_pos))
775 int LyXText::WidthOfCell(LyXParagraph * par,
776 LyXParagraph::size_type & pos) const
779 while (pos < par->Last() && !par->IsNewline(pos)) {
780 w += SingleWidth(par, pos);
783 if (par->IsNewline(pos))
789 bool LyXText::HitInTable(Row * row, int x) const
792 float fill_separator, fill_hfill, fill_label_hfill;
793 if (!row->par->table)
795 PrepareToPrint(row, tmpx, fill_separator,
796 fill_hfill, fill_label_hfill, false);
797 return (x > tmpx && x < tmpx + row->par->table->WidthOfTable());
801 bool LyXText::MouseHitInTable(int x, long y) const
803 Row * row = GetRowNearY(y);
804 return HitInTable(row, x);
808 /* table stuff -- end*/
811 // get the next breakpoint in a given paragraph
812 LyXParagraph::size_type
813 LyXText::NextBreakPoint(Row const * row, int width) const
815 LyXParagraph * par = row->par;
816 LyXParagraph::size_type pos = row->pos;
818 /* table stuff -- begin*/
820 while (pos < par->size()
821 && (!par->IsNewline(pos)
822 || !par->table->IsFirstCell(NumberOfCell(par, pos+1)))) {
823 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
824 par->GetInset(pos) && par->GetInset(pos)->display()){
825 par->GetInset(pos)->display(false);
831 /* table stuff -- end*/
833 // position of the last possible breakpoint
834 // -1 isn't a suitable value, but a flag
835 LyXParagraph::size_type last_separator = -1;
836 int left_margin = LabelEnd(row);
837 width -= RightMargin(row);
839 LyXParagraph::size_type main_body = BeginningOfMainBody(par);
840 LyXLayout const & layout =
841 textclasslist.Style(parameters->textclass, par->GetLayout());
842 LyXParagraph::size_type i = pos;
844 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
845 /* special code for right address boxes, only newlines count */
846 while (i < par->Last()) {
847 if (par->IsNewline(i)) {
849 i = par->Last() - 1; // this means break
851 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
852 par->GetInset(i) && par->GetInset(i)->display()){
853 par->GetInset(i)->display(false);
858 // Last position is an invariant
859 LyXParagraph::size_type const last =
861 // this is the usual handling
862 int x = LeftMargin(row);
863 while (x < width && i < last) {
864 char c = par->GetChar(i);
865 if (IsNewlineChar(c)) {
867 x = width; // this means break
868 } else if (c == LyXParagraph::META_INSET &&
869 par->GetInset(i) && par->GetInset(i)->display()){
870 // check wether a Display() inset is
871 // valid here. if not, change it to
873 if (layout.isCommand()
874 || (layout.labeltype == LABEL_MANUAL
875 && i < BeginningOfMainBody(par))){
876 // display istn't allowd
877 par->GetInset(i)->display(false);
878 x += SingleWidth(par, i, c);
880 // inset is display. So break the line here
884 if (IsLineSeparatorChar(par->GetChar(i+1)))
887 last_separator = last; // to avoid extra rows
889 last_separator = i - 1;
890 x = width; // this means break
893 if (IsLineSeparatorChar(c))
895 x += SingleWidth(par, i, c);
898 if (i == main_body) {
899 x += GetFont(par, -2).stringWidth(layout.labelsep);
900 if (par->IsLineSeparator(i - 1))
901 x-= SingleWidth(par, i - 1);
906 // end of paragraph is always a suitable separator
907 if (i == last && x < width)
911 // well, if last_separator is still 0, the line isn't breakable.
912 // don't care and cut simply at the end
913 if (last_separator < 0) {
917 // manual labels cannot be broken in LaTeX, do not care
918 if (main_body && last_separator < main_body)
919 last_separator = main_body - 1;
921 return last_separator;
925 // returns the minimum space a row needs on the screen in pixel
926 int LyXText::Fill(Row const * row, int paper_width) const
929 // get the pure distance
930 LyXParagraph::size_type last = RowLast(row);
931 /* table stuff -- begin */
932 if (row->par->table) {
933 // for tables FILL does calculate the widthes of each cell in
935 LyXParagraph::size_type pos = row->pos;
936 int cell = NumberOfCell(row->par, pos);
939 row->par->table->SetWidthOfCell(cell,
940 WidthOfCell(row->par,
943 } while (pos <= last && !row->par->table->IsFirstCell(cell));
944 // don't forget the very last table cell without characters
945 if (cell == row->par->table->GetNumberOfCells() - 1)
946 row->par->table->SetWidthOfCell(cell,
947 WidthOfCell(row->par,
950 return 0; /* width of table cannot be returned since
951 * we cannot guarantee its correct value at
954 /* table stuff -- end*/
956 int left_margin = LabelEnd(row);
958 // if the row ends with newline, this newline will not be relevant
959 //if (last >= 0 && row->par->IsNewline(last))
962 // if the row ends with a space, this space will not be relevant
963 if (last >= 0 && row->par->IsLineSeparator(last))
966 // special handling of the right address boxes
967 if (textclasslist.Style(parameters->textclass,
968 row->par->GetLayout()).margintype
969 == MARGIN_RIGHT_ADDRESS_BOX) {
970 int tmpfill = row->fill;
971 row->fill = 0; // the minfill in MarginLeft()
977 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
978 row->par->GetLayout());
979 LyXParagraph::size_type main_body =
980 BeginningOfMainBody(row->par);
981 LyXParagraph::size_type i = row->pos;
984 if (main_body > 0 && i == main_body) {
985 w += GetFont(row->par, -2).
986 stringWidth(layout.labelsep);
987 if (row->par->IsLineSeparator(i - 1))
988 w -= SingleWidth(row->par, i - 1);
992 w += SingleWidth(row->par, i);
995 if (main_body > 0 && main_body > last) {
996 w += GetFont(row->par, -2).stringWidth(layout.labelsep);
997 if (last >= 0 && row->par->IsLineSeparator(last))
998 w -= SingleWidth(row->par, last);
1003 fill = paper_width - w - RightMargin(row);
1008 // returns the minimum space a manual label needs on the screen in pixel
1009 int LyXText::LabelFill(Row const * row) const
1011 LyXParagraph::size_type last = BeginningOfMainBody(row->par) - 1;
1012 // -1 because a label ends either with a space that is in the label,
1013 // or with the beginning of a footnote that is outside the label.
1015 // I don't understand this code in depth, but sometimes "last" is
1016 // less than 0 and this causes a crash. This fix seems to work
1017 // correctly, but I bet the real error is elsewhere. The bug is
1018 // triggered when you have an open footnote in a paragraph
1019 // environment with a manual label. (Asger)
1020 if (last < 0) last = 0;
1022 if (row->par->IsLineSeparator(last)) /* a sepearator at this end
1029 w += SingleWidth(row->par, i);
1034 if (!row->par->labelwidthstring.empty()) {
1035 fill = GetFont(row->par, -2)
1036 .stringWidth(row->par->labelwidthstring) - w;
1046 // returns the number of separators in the specified row. The separator
1047 // on the very last column doesnt count
1048 int LyXText::NumberOfSeparators(Row const * row) const
1050 int last = RowLast(row);
1052 //int main_body = BeginningOfMainBody(row->par);
1053 //if (p < main_body)
1055 // I think this is equivalent to the above. (Lgb)
1056 int p = max(row->pos, BeginningOfMainBody(row->par));
1058 for (; p < last; ++p) {
1059 if (row->par->IsSeparator(p)) {
1067 // returns the number of hfills in the specified row. The LyX-Hfill is
1068 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1069 // ignored. This is *MUCH* more usefull than not to ignore!
1070 int LyXText::NumberOfHfills(Row const * row) const
1072 int last = RowLast(row);
1073 int first = row->pos;
1074 if (first) { /* hfill *DO* count at the beginning
1076 while(first <= last && row->par->IsHfill(first))
1080 //int main_body = BeginningOfMainBody(row->par);
1081 //if (first < main_body)
1082 // first = main_body;
1083 // I think this is equivalent to the above. (Lgb)
1084 first = max(first, BeginningOfMainBody(row->par));
1086 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1087 if (row->par->IsHfill(p)) {
1095 // like NumberOfHfills, but only those in the manual label!
1096 int LyXText::NumberOfLabelHfills(Row const * row) const
1098 LyXParagraph::size_type last = RowLast(row);
1099 LyXParagraph::size_type first = row->pos;
1100 if (first) { /* hfill *DO* count at the beginning
1102 while(first < last && row->par->IsHfill(first))
1105 //LyXParagraph::size_type main_body =
1106 //BeginningOfMainBody(row->par);
1107 //if (last > main_body)
1109 // I think this is eqvialent to the above. (Lgb)
1110 last = min(last, BeginningOfMainBody(row->par));
1112 for (LyXParagraph::size_type p = first;
1113 p < last; ++p) { // last, because the end is ignored!
1114 if (row->par->IsHfill(p)) {
1122 // returns true, if a expansion is needed.
1123 // Rules are given by LaTeX
1124 bool LyXText::HfillExpansion(Row const * row_ptr,
1125 LyXParagraph::size_type pos) const
1127 // by the way, is it a hfill?
1128 if (!row_ptr->par->IsHfill(pos))
1131 // at the end of a row it does not count
1132 if (pos >= RowLast(row_ptr))
1135 // at the beginning of a row it does not count, if it is not
1136 // the first row of a paragaph
1140 // in some labels it does not count
1141 if (textclasslist.Style(parameters->textclass,
1142 row_ptr->par->GetLayout()).margintype
1144 && pos < BeginningOfMainBody(row_ptr->par))
1147 // if there is anything between the first char of the row and
1148 // the sepcified position that is not a newline and not a hfill,
1149 // the hfill will count, otherwise not
1150 LyXParagraph::size_type i = row_ptr->pos;
1151 while (i < pos && (row_ptr->par->IsNewline(i)
1152 || row_ptr->par->IsHfill(i)))
1159 void LyXText::SetHeightOfRow(Row * row_ptr) const
1161 /* get the maximum ascent and the maximum descent */
1163 float layoutasc = 0;
1164 float layoutdesc = 0;
1169 /* this must not happen before the currentrow for clear reasons.
1170 so the trick is just to set the current row onto this row */
1172 GetRow(row_ptr->par, row_ptr->pos, unused_y);
1174 /* ok , let us initialize the maxasc and maxdesc value.
1175 * This depends in LaTeX of the font of the last character
1176 * in the paragraph. The hack below is necessary because
1177 * of the possibility of open footnotes */
1179 /* Correction: only the fontsize count. The other properties
1180 are taken from the layoutfont. Nicer on the screen :) */
1182 LyXParagraph * par = row_ptr->par->LastPhysicalPar();
1183 LyXParagraph * firstpar = row_ptr->par->FirstPhysicalPar();
1185 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
1186 firstpar->GetLayout());
1188 LyXFont font = GetFont(par, par->Last()-1);
1189 LyXFont::FONT_SIZE size = font.size();
1190 font = GetFont(par, -1);
1193 LyXFont labelfont = GetFont(par, -2);
1195 int maxasc = int(font.maxAscent() *
1196 layout.spacing.getValue() *
1197 parameters->spacing.getValue());
1198 int maxdesc = int(font.maxDescent() *
1199 layout.spacing.getValue() *
1200 parameters->spacing.getValue());
1202 int pos_end = RowLast(row_ptr);
1206 // Check if any insets are larger
1207 for (pos = row_ptr->pos; pos <= pos_end; ++pos) {
1208 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_INSET) {
1209 tmpfont = GetFont(row_ptr->par, pos);
1210 tmpinset = row_ptr->par->GetInset(pos);
1212 asc = tmpinset->ascent(owner_->painter(), tmpfont);
1213 desc = tmpinset->descent(owner_->painter(), tmpfont);
1222 // Check if any custom fonts are larger (Asger)
1223 // This is not completely correct, but we can live with the small,
1224 // cosmetic error for now.
1225 LyXFont::FONT_SIZE maxsize = row_ptr->par->HighestFontInRange(row_ptr->pos,
1227 if (maxsize > font.size()) {
1228 font.setSize(maxsize);
1230 asc = font.maxAscent();
1231 desc = font.maxDescent();
1238 /* table stuff -- begin*/
1239 if (row_ptr->par->table){
1240 // stretch the rows a bit
1244 /* table stuff -- end*/
1246 // This is nicer with box insets:
1250 row_ptr->ascent_of_text = maxasc;
1252 /* is it a top line? */
1253 if (row_ptr->pos == 0
1254 && row_ptr->par == firstpar) {
1256 /* some parksips VERY EASY IMPLEMENTATION */
1257 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
1258 if (layout.isParagraph()
1259 && firstpar->GetDepth() == 0
1260 && firstpar->Previous())
1261 maxasc += parameters->getDefSkip().inPixels();
1262 else if (firstpar->Previous()
1263 && textclasslist.Style(parameters->textclass,
1264 firstpar->Previous()->GetLayout()).isParagraph()
1265 && firstpar->Previous()->GetDepth() == 0)
1266 // is it right to use defskip here too? (AS)
1267 maxasc += parameters->getDefSkip().inPixels();
1270 /* the paper margins */
1271 if (!row_ptr->par->previous)
1272 maxasc += LYX_PAPER_MARGIN;
1274 /* add the vertical spaces, that the user added */
1275 if (firstpar->added_space_top.kind() != VSpace::NONE)
1276 maxasc += int(firstpar->added_space_top.inPixels());
1278 /* do not forget the DTP-lines!
1279 * there height depends on the font of the nearest character */
1280 if (firstpar->line_top)
1281 maxasc += 2 * GetFont(firstpar, 0).ascent('x');
1283 /* and now the pagebreaks */
1284 if (firstpar->pagebreak_top)
1285 maxasc += 3 * DefaultHeight();
1287 /* this is special code for the chapter, since the label of this
1288 * layout is printed in an extra row */
1289 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1290 && parameters->secnumdepth>= 0) {
1291 labeladdon = int(labelfont.maxDescent() *
1292 layout.spacing.getValue() *
1293 parameters->spacing.getValue())
1294 + int(labelfont.maxAscent() *
1295 layout.spacing.getValue() *
1296 parameters->spacing.getValue());
1299 /* special code for the top label */
1300 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1301 || layout.labeltype == LABEL_BIBLIO
1302 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1303 && row_ptr->par->IsFirstInSequence()
1304 && !row_ptr->par->GetLabestring().empty()) {
1306 (labelfont.maxAscent() *
1307 layout.spacing.getValue() *
1308 parameters->spacing.getValue())
1309 +(labelfont.maxDescent() *
1310 layout.spacing.getValue() *
1311 parameters->spacing.getValue())
1312 + layout.topsep * DefaultHeight()
1313 + layout.labelbottomsep * DefaultHeight());
1316 /* and now the layout spaces, for example before and after a section,
1317 * or between the items of a itemize or enumerate environment */
1319 if (!firstpar->pagebreak_top) {
1320 LyXParagraph * prev = row_ptr->par->Previous();
1322 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth());
1323 if (prev && prev->GetLayout() == firstpar->GetLayout()
1324 && prev->GetDepth() == firstpar->GetDepth()
1325 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1327 layoutasc = (layout.itemsep * DefaultHeight());
1329 else if (row_ptr->previous) {
1330 tmptop = layout.topsep;
1332 if (row_ptr->previous->par->GetDepth() >= row_ptr->par->GetDepth())
1333 tmptop-= textclasslist.Style(parameters->textclass, row_ptr->previous->par->GetLayout()).bottomsep;
1336 layoutasc = (tmptop * DefaultHeight());
1338 else if (row_ptr->par->line_top){
1339 tmptop = layout.topsep;
1342 layoutasc = (tmptop * DefaultHeight());
1345 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth()-1);
1347 maxasc += int(textclasslist.Style(parameters->textclass,
1348 prev->GetLayout()).parsep * DefaultHeight());
1351 if (firstpar->Previous()
1352 && firstpar->Previous()->GetDepth() == 0
1353 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1356 else if (firstpar->Previous()){
1357 maxasc += int(layout.parsep * DefaultHeight());
1363 /* is it a bottom line? */
1364 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
1365 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
1367 /* the paper margins */
1369 maxdesc += LYX_PAPER_MARGIN;
1371 /* add the vertical spaces, that the user added */
1372 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1373 maxdesc += int(firstpar->added_space_bottom.inPixels());
1375 /* do not forget the DTP-lines!
1376 * there height depends on the font of the nearest character */
1377 if (firstpar->line_bottom)
1378 maxdesc += 2 * (GetFont(par, par->Last()-1).ascent('x'));
1380 /* and now the pagebreaks */
1381 if (firstpar->pagebreak_bottom)
1382 maxdesc += 3 * DefaultHeight();
1384 /* and now the layout spaces, for example before and after a section,
1385 * or between the items of a itemize or enumerate environment */
1386 if (!firstpar->pagebreak_bottom && row_ptr->par->Next()) {
1387 LyXParagraph * nextpar = row_ptr->par->Next();
1388 LyXParagraph * comparepar = row_ptr->par;
1392 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1393 usual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1394 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1395 if (comparepar->GetLayout()!= nextpar->GetLayout()
1396 || nextpar->GetLabelWidthString() !=
1397 comparepar->GetLabelWidthString())
1398 unusual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1400 if (unusual > usual)
1401 layoutdesc = unusual;
1405 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1407 if (comparepar->GetLayout()!= nextpar->GetLayout()
1408 || nextpar->GetLabelWidthString() !=
1409 comparepar->GetLabelWidthString())
1410 layoutdesc = int(textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1415 /* incalculate the layout spaces */
1416 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1417 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1419 /* table stuff -- begin*/
1420 if (row_ptr->par->table){
1421 maxasc += row_ptr->par->table->
1422 AdditionalHeight(NumberOfCell(row_ptr->par, row_ptr->pos));
1424 /* table stuff -- end*/
1426 /* calculate the new height of the text */
1427 height -= row_ptr->height;
1429 row_ptr->height = maxasc + maxdesc + labeladdon;
1430 row_ptr->baseline = maxasc + labeladdon;
1432 height += row_ptr->height;
1436 /* Appends the implicit specified paragraph behind the specified row,
1437 * start at the implicit given position */
1438 void LyXText::AppendParagraph(Row * row) const
1440 bool not_ready = true;
1442 // The last character position of a paragraph is an invariant so we can
1443 // safely get it here. (Asger)
1444 int lastposition = row->par->Last();
1447 // Get the next breakpoint
1448 int z = NextBreakPoint(row, paperwidth);
1452 // Insert the new row
1453 if (z < lastposition) {
1455 InsertRow(row, row->par, z);
1462 // Set the dimensions of the row
1463 tmprow->fill = Fill(tmprow, paperwidth);
1464 SetHeightOfRow(tmprow);
1466 } while (not_ready);
1470 void LyXText::BreakAgain(Row * row) const
1472 bool not_ready = true;
1475 /* get the next breakpoint */
1476 LyXParagraph::size_type z =
1477 NextBreakPoint(row, paperwidth);
1480 if (z < row->par->Last() ) {
1481 if (!row->next || (row->next && row->next->par != row->par)) {
1484 InsertRow(row, row->par, z);
1491 not_ready = false; // the rest will not change
1497 /* if there are some rows too much, delete them */
1498 /* only if you broke the whole paragraph! */
1499 Row * tmprow2 = row;
1500 while (tmprow2->next && tmprow2->next->par == row->par) {
1501 tmprow2 = tmprow2->next;
1503 while (tmprow2 != row) {
1504 tmprow2 = tmprow2->previous;
1505 RemoveRow(tmprow2->next);
1510 /* set the dimensions of the row */
1511 tmprow->fill = Fill(tmprow, paperwidth);
1512 SetHeightOfRow(tmprow);
1513 } while (not_ready);
1517 /* this is just a little changed version of break again */
1518 void LyXText::BreakAgainOneRow(Row * row)
1520 /* get the next breakpoint */
1521 LyXParagraph::size_type z = NextBreakPoint(row, paperwidth);
1524 if (z < row->par->Last() ) {
1525 if (!row->next || (row->next && row->next->par != row->par)) {
1526 /* insert a new row */
1528 InsertRow(row, row->par, z);
1540 /* if there are some rows too much, delete them */
1541 /* only if you broke the whole paragraph! */
1542 Row * tmprow2 = row;
1543 while (tmprow2->next && tmprow2->next->par == row->par) {
1544 tmprow2 = tmprow2->next;
1546 while (tmprow2 != row) {
1547 tmprow2 = tmprow2->previous;
1548 RemoveRow(tmprow2->next);
1552 /* set the dimensions of the row */
1553 tmprow->fill = Fill(tmprow, paperwidth);
1554 SetHeightOfRow(tmprow);
1558 void LyXText::BreakParagraph(char keep_layout)
1560 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
1561 cursor.par->GetLayout());
1563 /* table stuff -- begin */
1564 if (cursor.par->table) {
1565 // breaking of tables is only allowed at the beginning or the end */
1566 if (cursor.pos && cursor.pos < cursor.par->size() &&
1567 !cursor.par->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par, cursor.pos)))
1568 return; // no breaking of tables allowed
1570 /* table stuff -- end */
1572 // this is only allowed, if the current paragraph is not empty or caption
1573 if ((cursor.par->Last() <= 0 && !cursor.par->IsDummy())
1575 layout.labeltype!= LABEL_SENSITIVE)
1578 SetUndo(Undo::INSERT,
1579 cursor.par->ParFromPos(cursor.pos)->previous,
1580 cursor.par->ParFromPos(cursor.pos)->next);
1582 /* table stuff -- begin */
1583 if (cursor.par->table) {
1584 int cell = NumberOfCell(cursor.par, cursor.pos);
1585 if (cursor.par->table->ShouldBeVeryLastCell(cell))
1586 SetCursor(cursor.par, cursor.par->text.size());
1588 /* table stuff -- end */
1590 // please break always behind a space
1591 if (cursor.pos < cursor.par->Last()
1592 && cursor.par->IsLineSeparator(cursor.pos))
1595 // break the paragraph
1599 keep_layout = layout.isEnvironment();
1600 cursor.par->BreakParagraph(cursor.pos, keep_layout);
1602 /* table stuff -- begin */
1603 if (cursor.par->table){
1604 // the table should stay with the contents
1606 cursor.par->Next()->table = cursor.par->table;
1607 cursor.par->table = 0;
1610 /* table stuff -- end */
1612 // well this is the caption hack since one caption is really enough
1613 if (layout.labeltype == LABEL_SENSITIVE){
1615 cursor.par->SetLayout(0); // set to standard-layout
1617 cursor.par->Next()->SetLayout(0); // set to standard-layout
1620 /* if the cursor is at the beginning of a row without prior newline,
1622 * This touches only the screen-update. Otherwise we would may have
1623 * an empty row on the screen */
1624 if (cursor.pos && !cursor.row->par->IsNewline(cursor.row->pos -1) &&
1625 cursor.row->pos == cursor.pos) {
1629 status = LyXText::NEED_MORE_REFRESH;
1630 refresh_row = cursor.row;
1631 refresh_y = cursor.y - cursor.row->baseline;
1633 // Do not forget the special right address boxes
1634 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1635 while (refresh_row->previous &&
1636 refresh_row->previous->par == refresh_row->par) {
1637 refresh_row = refresh_row->previous;
1638 refresh_y -= refresh_row->height;
1641 RemoveParagraph(cursor.row);
1643 // set the dimensions of the cursor row
1644 cursor.row->fill = Fill(cursor.row, paperwidth);
1646 SetHeightOfRow(cursor.row);
1648 while (!cursor.par->Next()->table && cursor.par->Next()->Last()
1649 && cursor.par->Next()->IsNewline(0))
1650 cursor.par->Next()->Erase(0);
1652 InsertParagraph(cursor.par->Next(), cursor.row);
1654 UpdateCounters(cursor.row->previous);
1656 /* This check is necessary. Otherwise the new empty paragraph will
1657 * be deleted automatically. And it is more friendly for the user! */
1659 SetCursor(cursor.par->Next(), 0);
1661 SetCursor(cursor.par, 0);
1663 if (cursor.row->next)
1664 BreakAgain(cursor.row->next);
1670 void LyXText::OpenFootnote()
1672 LyXParagraph * endpar,* tmppar;
1675 LyXParagraph * par = cursor.par->ParFromPos(cursor.pos);
1677 /* if there is no footnote in this paragraph, just return. */
1679 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1682 /* ok, move the cursor right before the footnote */
1684 /* just a little faster than using CursorRight() */
1685 for (cursor.pos = 0;
1686 cursor.par->ParFromPos(cursor.pos) != par; cursor.pos++);
1687 /* now the cursor is at the beginning of the physical par */
1688 SetCursor(cursor.par,
1689 cursor.pos + cursor.par->ParFromPos(cursor.pos)->text.size());
1691 /* the cursor must be exactly before the footnote */
1692 par = cursor.par->ParFromPos(cursor.pos);
1694 status = LyXText::NEED_MORE_REFRESH;
1695 refresh_row = cursor.row;
1696 refresh_y = cursor.y - cursor.row->baseline;
1698 tmppar = cursor.par;
1699 endpar = cursor.par->Next();
1702 tmppar->OpenFootnote(cursor.pos);
1703 RemoveParagraph(row);
1704 /* set the dimensions of the cursor row */
1705 row->fill = Fill(row, paperwidth);
1706 SetHeightOfRow(row);
1707 tmppar = tmppar->Next();
1709 while (tmppar != endpar) {
1711 InsertParagraph(tmppar, row);
1712 while (row->next && row->next->par == tmppar)
1714 tmppar = tmppar->Next();
1717 SetCursor(par->next, 0);
1718 sel_cursor = cursor;
1722 /* table stuff -- begin*/
1724 void LyXText::TableFeatures(int feature, string const & val) const
1726 if (!cursor.par->table)
1727 return; /* this should never happen */
1729 int actCell = NumberOfCell(cursor.par, cursor.pos);
1730 SetUndo(Undo::FINISH,
1731 cursor.par->ParFromPos(cursor.pos)->previous,
1732 cursor.par->ParFromPos(cursor.pos)->next);
1735 case LyXTable::SET_PWIDTH:
1736 cursor.par->table->SetPWidth(actCell, val);
1738 case LyXTable::SET_SPECIAL_COLUMN:
1739 case LyXTable::SET_SPECIAL_MULTI:
1740 cursor.par->table->SetAlignSpecial(actCell, val, feature);
1749 void LyXText::TableFeatures(int feature) const
1752 int setAlign = LYX_ALIGN_LEFT;
1756 if (!cursor.par->table)
1757 return; /* this should never happen */
1759 int actCell = NumberOfCell(cursor.par, cursor.pos);
1760 SetUndo(Undo::FINISH,
1761 cursor.par->ParFromPos(cursor.pos)->previous,
1762 cursor.par->ParFromPos(cursor.pos)->next);
1765 case LyXTable::ALIGN_LEFT:
1766 setAlign= LYX_ALIGN_LEFT;
1768 case LyXTable::ALIGN_RIGHT:
1769 setAlign= LYX_ALIGN_RIGHT;
1771 case LyXTable::ALIGN_CENTER:
1772 setAlign= LYX_ALIGN_CENTER;
1778 case LyXTable::APPEND_ROW: {
1779 LyXParagraph::size_type pos = cursor.pos;
1781 /* move to the next row */
1782 int cell_org = actCell;
1783 int cell = cell_org;
1785 // if there is a ContRow following this row I have to add
1786 // the row after the ContRow's
1787 if ((pos < cursor.par->Last()) &&
1788 cursor.par->table->RowHasContRow(cell_org)) {
1789 while((pos < cursor.par->Last()) &&
1790 !cursor.par->table->IsContRow(cell)) {
1791 while (pos < cursor.par->Last() &&
1792 !cursor.par->IsNewline(pos))
1794 if (pos < cursor.par->Last())
1798 while((pos < cursor.par->Last()) &&
1799 cursor.par->table->IsContRow(cell)) {
1800 while (pos < cursor.par->Last() &&
1801 !cursor.par->IsNewline(pos))
1803 if (pos < cursor.par->Last())
1808 if (pos < cursor.par->Last())
1811 while (pos < cursor.par->Last() &&
1812 (cell == cell_org || !cursor.par->table->IsFirstCell(cell))){
1813 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1815 if (pos < cursor.par->Last())
1820 /* insert the new cells */
1821 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1822 for (int i = 0; i < number; ++i)
1823 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1825 /* append the row into the table */
1826 cursor.par->table->AppendRow(cell_org);
1830 case LyXTable::APPEND_CONT_ROW: {
1831 LyXParagraph::size_type pos = cursor.pos;
1832 /* move to the next row */
1833 int cell_org = actCell;
1834 int cell = cell_org;
1836 // if there is already a controw but not for this cell
1837 // the AppendContRow sets only the right values but does
1838 // not actually add a row
1839 if (cursor.par->table->RowHasContRow(cell_org) &&
1840 (cursor.par->table->CellHasContRow(cell_org)<0)) {
1841 cursor.par->table->AppendContRow(cell_org);
1845 while (pos < cursor.par->Last() &&
1847 || !cursor.par->table->IsFirstCell(cell))){
1848 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1850 if (pos < cursor.par->Last())
1855 /* insert the new cells */
1856 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1857 for (int i = 0; i < number; ++i)
1858 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1860 /* append the row into the table */
1861 cursor.par->table->AppendContRow(cell_org);
1865 case LyXTable::APPEND_COLUMN: {
1866 LyXParagraph::size_type pos = 0;
1867 int cell_org = actCell;
1870 if (pos && (cursor.par->IsNewline(pos-1))){
1871 if (cursor.par->table->AppendCellAfterCell(cell_org, cell)){
1872 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1873 if (pos <= cursor.pos)
1880 } while (pos <= cursor.par->Last());
1881 /* remember that the very last cell doesn't end with a newline.
1882 This saves one byte memory per table ;-) */
1883 if (cursor.par->table->AppendCellAfterCell(cell_org, cell))
1884 cursor.par->InsertChar(cursor.par->Last(), LyXParagraph::META_NEWLINE);
1886 /* append the column into the table */
1887 cursor.par->table->AppendColumn(cell_org);
1892 case LyXTable::DELETE_ROW:
1893 if (current_view->the_locking_inset)
1894 current_view->unlockInset(current_view->the_locking_inset);
1895 RemoveTableRow(&cursor);
1899 case LyXTable::DELETE_COLUMN: {
1900 LyXParagraph::size_type pos = 0;
1901 int cell_org = actCell;
1903 if (current_view->the_locking_inset)
1904 current_view->unlockInset(current_view->the_locking_inset);
1906 if (!pos || (cursor.par->IsNewline(pos-1))){
1907 if (cursor.par->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
1909 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1910 cursor.par->Erase(pos);
1911 if (pos < cursor.par->Last())
1912 cursor.par->Erase(pos);
1914 cursor.par->Erase(pos - 1); // the missing newline at the end of a table
1915 --pos; // because of pos++ below
1920 } while (pos <= cursor.par->Last());
1922 /* delete the column from the table */
1923 cursor.par->table->DeleteColumn(cell_org);
1925 /* set the cursor to the beginning of the table, where else? */
1930 case LyXTable::TOGGLE_LINE_TOP:
1931 lineSet = !cursor.par->table->TopLine(actCell);
1933 cursor.par->table->SetTopLine(actCell, lineSet);
1935 LyXParagraph::size_type i;
1937 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
1938 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
1939 cursor.par->table->SetTopLine(n, lineSet);
1947 case LyXTable::TOGGLE_LINE_BOTTOM:
1948 lineSet = !cursor.par->table->BottomLine(actCell);
1950 cursor.par->table->SetBottomLine(actCell, lineSet);
1952 LyXParagraph::size_type i;
1954 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
1955 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
1956 cursor.par->table->SetBottomLine(n, lineSet);
1964 case LyXTable::TOGGLE_LINE_LEFT:
1965 lineSet = !cursor.par->table->LeftLine(actCell);
1967 cursor.par->table->SetLeftLine(actCell, lineSet);
1969 LyXParagraph::size_type i;
1971 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
1972 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1973 cursor.par->table->SetLeftLine(n, lineSet);
1981 case LyXTable::TOGGLE_LINE_RIGHT:
1982 lineSet = !cursor.par->table->RightLine(actCell);
1984 cursor.par->table->SetRightLine(actCell, lineSet);
1987 LyXParagraph::size_type i = sel_start_cursor.pos;
1988 for (; i <= sel_end_cursor.pos; ++i) {
1989 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1990 cursor.par->table->SetRightLine(n, lineSet);
1998 case LyXTable::ALIGN_LEFT:
1999 case LyXTable::ALIGN_RIGHT:
2000 case LyXTable::ALIGN_CENTER:
2002 cursor.par->table->SetAlignment(actCell, setAlign);
2005 LyXParagraph::size_type i = sel_start_cursor.pos;
2006 for (; i <= sel_end_cursor.pos; ++i) {
2007 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2008 cursor.par->table->SetAlignment(n, setAlign);
2016 case LyXTable::DELETE_TABLE:
2017 SetCursorIntern(cursor.par, 0);
2018 delete cursor.par->table;
2019 cursor.par->table = 0;
2020 // temporary: Should put table in simple_cut_buffer (with before and after
2021 // dummy-paragraph !!
2022 // not necessar anymore with UNDO :)
2023 for (LyXParagraph::size_type i =
2024 cursor.par->text.size() - 1; i >= 0; --i)
2025 cursor.par->Erase(i);
2029 case LyXTable::MULTICOLUMN: {
2031 // check wether we are completly in a multicol
2032 int multicol = cursor.par->table->IsMultiColumn(actCell);
2033 if (multicol && selection && sel_start_cursor.row == sel_end_cursor.row){
2034 multicol = NumberOfCell(sel_start_cursor.par, sel_start_cursor.pos)
2035 == NumberOfCell(sel_end_cursor.par, sel_end_cursor.pos);
2039 int newlines = cursor.par->table->UnsetMultiColumn(actCell);
2040 LyXParagraph::size_type pos = cursor.pos;
2041 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
2043 for (; newlines; --newlines)
2044 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
2049 // selection must be in one row (or no selection)
2051 cursor.par->table->SetMultiColumn(NumberOfCell(cursor.par,
2058 if (sel_start_cursor.row == sel_end_cursor.row){
2059 LyXParagraph::size_type i;
2061 for (i = sel_start_cursor.pos;
2062 i < sel_end_cursor.pos; ++i){
2063 if (sel_start_cursor.par->IsNewline(i)){
2064 sel_start_cursor.par->Erase(i);
2065 // check for double-blanks
2066 if ((i && !sel_start_cursor.par->IsLineSeparator(i-1))
2068 (i < sel_start_cursor.par->Last()
2069 && !sel_start_cursor.par->IsLineSeparator(i)))
2070 sel_start_cursor.par->InsertChar(i, ' ');
2072 sel_end_cursor.pos--;
2079 SetMultiColumn(NumberOfCell(sel_start_cursor.par,
2080 sel_start_cursor.pos),
2082 cursor.pos = sel_start_cursor.pos;
2087 WriteAlert(_("Impossible Operation!"),
2088 _("Multicolumns can only be horizontally."),
2095 case LyXTable::SET_ALL_LINES:
2097 case LyXTable::UNSET_ALL_LINES:
2099 cursor.par->table->SetAllLines(NumberOfCell(cursor.par,
2103 LyXParagraph::size_type i;
2105 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2106 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2107 cursor.par->table->SetAllLines(n, setLines);
2114 case LyXTable::SET_LONGTABLE:
2115 cursor.par->table->SetLongTable(true);
2117 case LyXTable::UNSET_LONGTABLE:
2118 cursor.par->table->SetLongTable(false);
2120 case LyXTable::SET_ROTATE_TABLE:
2121 cursor.par->table->SetRotateTable(true);
2123 case LyXTable::UNSET_ROTATE_TABLE:
2124 cursor.par->table->SetRotateTable(false);
2126 case LyXTable::SET_ROTATE_CELL:
2128 cursor.par->table->SetRotateCell(actCell, true);
2130 LyXParagraph::size_type i;
2132 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
2133 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2134 cursor.par->table->SetRotateCell(n, true);
2140 case LyXTable::UNSET_ROTATE_CELL:
2142 cursor.par->table->SetRotateCell(actCell, false);
2145 LyXParagraph::size_type i = sel_start_cursor.pos;
2146 for (; i <= sel_end_cursor.pos; ++i) {
2147 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2148 cursor.par->table->SetRotateCell(n, false);
2154 case LyXTable::SET_LINEBREAKS:
2155 what = !cursor.par->table->Linebreaks(cursor.par->table->FirstVirtualCell(actCell));
2157 cursor.par->table->SetLinebreaks(actCell, what);
2159 LyXParagraph::size_type i;
2161 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2162 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2163 cursor.par->table->SetLinebreaks(n, what);
2169 case LyXTable::SET_LTFIRSTHEAD:
2170 cursor.par->table->SetLTHead(actCell, true);
2172 case LyXTable::SET_LTHEAD:
2173 cursor.par->table->SetLTHead(actCell, false);
2175 case LyXTable::SET_LTFOOT:
2176 cursor.par->table->SetLTFoot(actCell, false);
2178 case LyXTable::SET_LTLASTFOOT:
2179 cursor.par->table->SetLTFoot(actCell, true);
2181 case LyXTable::SET_LTNEWPAGE:
2182 what = !cursor.par->table->LTNewPage(actCell);
2183 cursor.par->table->SetLTNewPage(actCell, what);
2189 void LyXText::InsertCharInTable(char c)
2194 bool jumped_over_space;
2196 /* first check, if there will be two blanks together or a blank at
2197 * the beginning of a paragraph.
2198 * I decided to handle blanks like normal characters, the main
2199 * difference are the special checks when calculating the row.fill
2200 * (blank does not count at the end of a row) and the check here */
2202 LyXFont realtmpfont = real_current_font;
2203 LyXFont rawtmpfont = current_font; /* store the current font.
2204 * This is because of the use
2205 * of cursor movements. The moving
2206 * cursor would refresh the
2209 // Get the font that is used to calculate the baselineskip
2210 LyXParagraph::size_type const lastpos =
2212 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2214 jumped_over_space = false;
2215 if (IsLineSeparatorChar(c)) {
2217 #ifndef FIX_DOUBLE_SPACE
2218 /* avoid double blanks but insert the new blank because
2219 * of a possible font change */
2220 if (cursor.pos < lastpos &&
2221 cursor.par->IsLineSeparator(cursor.pos)) {
2222 cursor.par->Erase(cursor.pos);
2223 jumped_over_space = true;
2226 if ((cursor.pos > 0 &&
2227 cursor.par->IsLineSeparator(cursor.pos - 1))
2228 || (cursor.pos > 0 && cursor.par->IsNewline(cursor.pos - 1))
2229 || (cursor.pos == 0 &&
2230 !(cursor.par->Previous()
2231 && cursor.par->Previous()->footnoteflag
2232 == LyXParagraph::OPEN_FOOTNOTE)))
2234 } else if (IsNewlineChar(c)) {
2235 if (!IsEmptyTableCell()) {
2236 TableFeatures(LyXTable::APPEND_CONT_ROW);
2243 y = cursor.y - row->baseline;
2244 if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset
2245 * already inserted the character */
2246 cursor.par->InsertChar(cursor.pos, c);
2247 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2249 if (!jumped_over_space) {
2250 /* refresh the positions */
2252 while (tmprow->next && tmprow->next->par == row->par) {
2253 tmprow = tmprow->next;
2260 CheckParagraphInTable(cursor.par, cursor.pos);
2262 current_font = rawtmpfont;
2263 real_current_font = realtmpfont;
2265 /* check, whether the last character's font has changed. */
2266 if (cursor.pos && cursor.pos == cursor.par->Last()
2267 && rawparfont != rawtmpfont)
2268 RedoHeightOfParagraph(cursor);
2272 void LyXText::CheckParagraphInTable(LyXParagraph * par,
2273 LyXParagraph::size_type pos)
2276 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
2277 par->GetInset(pos) && par->GetInset(pos)->display()){
2278 par->GetInset(pos)->display(false);
2282 Row * row = GetRow(par, pos, y);
2284 int tmpheight = row->height;
2285 SetHeightOfRow(row);
2287 LyXParagraph::size_type tmp_pos = pos;
2288 /* update the table information */
2289 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2291 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2292 WidthOfCell(par, tmp_pos))) {
2293 LyXCursor tmpcursor = cursor;
2294 SetCursorIntern(par, pos);
2295 /* make a complete redraw */
2296 RedoDrawingOfParagraph(cursor);
2300 /* redraw only the row */
2301 LyXCursor tmpcursor = cursor;
2302 SetCursorIntern(par, pos);
2304 refresh_x = cursor.x;
2306 refresh_pos = cursor.pos;
2309 if (tmpheight == row->height)
2310 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2312 status = LyXText::NEED_MORE_REFRESH;
2314 SetCursorIntern(cursor.par, cursor.pos);
2318 void LyXText::BackspaceInTable()
2320 Row * tmprow, * row;
2323 LyXFont rawtmpfont = current_font;
2324 LyXFont realtmpfont = real_current_font;
2326 // Get the font that is used to calculate the baselineskip
2327 int const lastpos = cursor.par->Last();
2328 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2330 if (cursor.pos == 0) {
2331 /* no pasting of table paragraphs */
2335 /* this is the code for a normal backspace, not pasting
2337 SetUndo(Undo::DELETE,
2338 cursor.par->ParFromPos(cursor.pos)->previous,
2339 cursor.par->ParFromPos(cursor.pos)->next);
2343 /* some insets are undeletable here */
2344 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
2345 if (!cursor.par->GetInset(cursor.pos)->Deletable())
2350 y = cursor.y - row->baseline;
2352 /* some special code when deleting a newline. */
2353 if (cursor.par->IsNewline(cursor.pos)) {
2358 cursor.par->Erase(cursor.pos);
2360 /* refresh the positions */
2362 while (tmprow->next && tmprow->next->par == row->par) {
2363 tmprow = tmprow->next;
2367 #ifndef FIX_DOUBLE_SPACE
2368 /* delete superfluous blanks */
2369 if (cursor.pos < cursor.par->Last() - 1 &&
2370 (cursor.par->IsLineSeparator(cursor.pos))) {
2372 if (cursor.pos == BeginningOfMainBody(cursor.par)
2374 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
2375 cursor.par->Erase(cursor.pos);
2376 /* refresh the positions */
2378 while (tmprow->next &&
2379 tmprow->next->par == row->par) {
2380 tmprow = tmprow->next;
2383 if (cursor.pos) /* move one character left */
2390 CheckParagraphInTable(cursor.par, cursor.pos);
2392 /* check, wether the last characters font has changed. */
2393 if (cursor.pos && cursor.pos == cursor.par->Last()
2394 && rawparfont != rawtmpfont)
2395 RedoHeightOfParagraph(cursor);
2397 /* restore the current font
2398 * That is what a user expects! */
2399 current_font = rawtmpfont;
2400 real_current_font = realtmpfont;
2402 SetCursorIntern(cursor.par, cursor.pos);
2405 /* table stuff -- end*/
2408 /* just a macro to make some thing easier. */
2409 void LyXText::RedoParagraph() const
2412 // I suspect this version will work
2415 RedoParagraphs(cursor, cursor.par->Next());
2416 SetCursorIntern(cursor.par, cursor.pos);
2418 LyXCursor tmpcursor = cursor;
2420 RedoParagraphs(cursor, cursor.par->Next());
2421 SetCursorIntern(tmpcursor.par, tmpcursor.pos);
2426 /* insert a character, moves all the following breaks in the
2427 * same Paragraph one to the right and make a rebreak */
2428 void LyXText::InsertChar(char c)
2430 SetUndo(Undo::INSERT,
2431 cursor.par->ParFromPos(cursor.pos)->previous,
2432 cursor.par->ParFromPos(cursor.pos)->next);
2434 /* When the free-spacing option is set for the current layout,
2435 * all spaces are converted to protected spaces. */
2436 bool freeSpacingBo =
2437 textclasslist.Style(parameters->textclass,
2438 cursor.row->par->GetLayout()).free_spacing;
2440 if (freeSpacingBo && IsLineSeparatorChar(c)
2441 && (!cursor.pos || cursor.par->IsLineSeparator(cursor.pos - 1)))
2442 c = LyXParagraph::META_PROTECTED_SEPARATOR;
2444 /* table stuff -- begin*/
2445 if (cursor.par->table) {
2446 InsertCharInTable(c);
2450 /* table stuff -- end*/
2452 /* First check, if there will be two blanks together or a blank at
2453 the beginning of a paragraph.
2454 I decided to handle blanks like normal characters, the main
2455 difference are the special checks when calculating the row.fill
2456 (blank does not count at the end of a row) and the check here */
2458 // The bug is triggered when we type in a description environment:
2459 // The current_font is not changed when we go from label to main text
2460 // and it should (along with realtmpfont) when we type the space.
2461 #ifdef WITH_WARNINGS
2462 #warning There is a bug here! (Asger)
2465 LyXFont realtmpfont = real_current_font;
2466 LyXFont rawtmpfont = current_font; /* store the current font.
2467 * This is because of the use
2468 * of cursor movements. The moving
2469 * cursor would refresh the
2472 // Get the font that is used to calculate the baselineskip
2473 LyXParagraph::size_type lastpos = cursor.par->Last();
2474 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2476 bool jumped_over_space = false;
2478 if (IsLineSeparatorChar(c)) {
2479 #ifndef FIX_DOUBLE_SPACE
2480 if (cursor.pos < lastpos
2481 && cursor.par->IsLineSeparator(cursor.pos)) {
2482 /* the user inserted a space before a space. So we
2483 * will just make a CursorRight. BUT: The font of this
2484 * space should be set to current font. That is why
2485 * we need to rebreak perhaps. If there is a protected
2486 * blank at the end of a row we have to force
2489 current_view->owner()->getMiniBuffer()
2490 ->Set(_("You cannot type two spaces this way. "
2491 " Please read the Tutorial."));
2493 // How can this ever happen?
2494 if (cursor.pos == RowLast(cursor.row)
2495 && !IsLineSeparatorChar(c))
2496 cursor.row->fill = -1; // force rebreak
2497 cursor.par->Erase(cursor.pos);
2498 jumped_over_space = true;
2500 // Seems to me that this works just as well.
2508 && cursor.par->IsLineSeparator(cursor.pos - 1))
2510 && cursor.par->IsNewline(cursor.pos - 1))
2512 && !(cursor.par->Previous()
2513 && cursor.par->Previous()->footnoteflag
2514 == LyXParagraph::OPEN_FOOTNOTE))) {
2515 if (cursor.pos == 0 )
2516 current_view->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2518 current_view->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2522 } else if (IsNewlineChar(c)) {
2523 if (cursor.par->FirstPhysicalPar() == cursor.par
2524 && cursor.pos <= BeginningOfMainBody(cursor.par)) {
2528 /* No newline at first position
2529 * of a paragraph or behind labels.
2530 * TeX does not allow that. */
2532 if (cursor.pos < cursor.par->Last() &&
2533 cursor.par->IsLineSeparator(cursor.pos))
2534 CursorRightIntern(); // newline always after a blank!
2535 cursor.row->fill = -1; // to force a new break
2538 // the display inset stuff
2539 if (cursor.row->par->GetChar(cursor.row->pos) == LyXParagraph::META_INSET
2540 && cursor.row->par->GetInset(cursor.row->pos)
2541 && cursor.row->par->GetInset(cursor.row->pos)->display())
2542 cursor.row->fill = -1; // to force a new break
2544 // get the cursor row fist
2545 Row * row = cursor.row;
2546 long y = cursor.y - row->baseline;
2547 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2548 * already insertet the character */
2549 cursor.par->InsertChar(cursor.pos, c);
2550 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2552 if (!jumped_over_space) {
2553 // refresh the positions
2555 while (tmprow->next && tmprow->next->par == row->par) {
2556 tmprow = tmprow->next;
2561 // Is there a break one row above
2562 if ((cursor.par->IsLineSeparator(cursor.pos)
2563 || cursor.par->IsNewline(cursor.pos)
2564 || cursor.row->fill == -1)
2565 && row->previous && row->previous->par == row->par) {
2566 LyXParagraph::size_type z = NextBreakPoint(row->previous,
2568 if ( z >= row->pos) {
2571 // set the dimensions of the row above
2572 row->previous->fill = Fill(row->previous, paperwidth);
2574 SetHeightOfRow(row->previous);
2576 y -= row->previous->height;
2578 refresh_row = row->previous;
2579 status = LyXText::NEED_MORE_REFRESH;
2581 BreakAgainOneRow(row);
2583 current_font = rawtmpfont;
2584 real_current_font = realtmpfont;
2585 SetCursor(cursor.par, cursor.pos + 1, false);
2586 /* cursor MUST be in row now */
2588 if (row->next && row->next->par == row->par)
2589 need_break_row = row->next;
2593 // check, wether the last characters font has changed.
2594 if (cursor.pos && cursor.pos == cursor.par->Last()
2595 && rawparfont != rawtmpfont)
2596 RedoHeightOfParagraph(cursor);
2603 /* recalculate the fill of the row */
2604 if (row->fill >= 0) /* needed because a newline
2605 * will set fill to -1. Otherwise
2606 * we would not get a rebreak! */
2607 row->fill = Fill(row, paperwidth);
2608 if (row->fill < 0 ) {
2611 refresh_x = cursor.x;
2612 refresh_pos = cursor.pos;
2613 status = LyXText::NEED_MORE_REFRESH;
2614 BreakAgainOneRow(row);
2615 /* will the cursor be in another row now? */
2616 if (RowLast(row) <= cursor.pos + 1 && row->next) {
2617 if (row->next && row->next->par == row->par)
2621 BreakAgainOneRow(row);
2623 current_font = rawtmpfont;
2624 real_current_font = realtmpfont;
2625 SetCursor(cursor.par, cursor.pos + 1, false);
2626 if (row->next && row->next->par == row->par)
2627 need_break_row = row->next;
2632 refresh_x = cursor.x;
2634 refresh_pos = cursor.pos;
2636 int tmpheight = row->height;
2637 SetHeightOfRow(row);
2638 if (tmpheight == row->height)
2639 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2641 status = LyXText::NEED_MORE_REFRESH;
2643 current_font = rawtmpfont;
2644 real_current_font = realtmpfont;
2645 SetCursor(cursor.par, cursor.pos + 1, false);
2648 /* check, wether the last characters font has changed. */
2649 if (cursor.pos && cursor.pos == cursor.par->Last()
2650 && rawparfont != rawtmpfont) {
2651 RedoHeightOfParagraph(cursor);
2653 /* now the special right address boxes */
2654 if (textclasslist.Style(parameters->textclass,
2655 cursor.par->GetLayout()).margintype
2656 == MARGIN_RIGHT_ADDRESS_BOX) {
2657 RedoDrawingOfParagraph(cursor);
2665 void LyXText::charInserted()
2667 // Here we could call FinishUndo for every 20 characters inserted.
2668 // This is from my experience how emacs does it.
2669 static unsigned int counter = 0;
2678 void LyXText::PrepareToPrint(Row * row, float & x,
2679 float & fill_separator,
2681 float & fill_label_hfill,
2686 float w = row->fill;
2688 fill_label_hfill = 0;
2690 fill_label_hfill = 0;
2692 LyXDirection direction = row->par->getParDirection();
2694 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
2695 x = RightMargin(row);
2696 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2697 LyXFont font(LyXFont::ALL_SANE);
2698 font.setSize(LyXFont::SIZE_SMALL);
2699 x += font.textWidth("Mwide-figM", 10);
2703 x = LeftMargin(row);
2705 /* is there a manual margin with a manual label */
2706 if (textclasslist.Style(parameters->textclass,
2707 row->par->GetLayout()).margintype == MARGIN_MANUAL
2708 && textclasslist.Style(parameters->textclass,
2709 row->par->GetLayout()).labeltype == LABEL_MANUAL) {
2711 nlh = NumberOfLabelHfills(row) + 1; /* one more since labels
2712 * are left aligned*/
2713 if (nlh && !row->par->GetLabelWidthString().empty()) {
2714 fill_label_hfill = LabelFill(row) / nlh;
2718 /* are there any hfills in the row? */
2719 nh = NumberOfHfills(row);
2721 /* table stuff -- begin*/
2722 if (row->par->table) {
2723 w = paperwidth - row->par->table->WidthOfTable()
2724 - x - RightMargin(row);
2725 nh = 0; /* ignore hfills in tables */
2727 /* table stuff -- end*/
2732 /* is it block, flushleft or flushright?
2733 * set x how you need it */
2735 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2736 align = textclasslist.Style(parameters->textclass, row->par->GetLayout()).align;
2738 align = row->par->FirstPhysicalPar()->align;
2740 /* center displayed insets */
2741 if (row->par->GetChar(row->pos) == LyXParagraph::META_INSET
2742 && row->par->GetInset(row->pos)
2743 && row->par->GetInset(row->pos)->display())
2744 align = LYX_ALIGN_CENTER;
2747 case LYX_ALIGN_BLOCK:
2748 ns = NumberOfSeparators(row);
2749 if (ns && row->next && row->next->par == row->par &&
2750 !(row->next->par->IsNewline(row->next->pos-1))
2751 && !(row->next->par->GetChar(row->next->pos) == LyXParagraph::META_INSET
2752 && row->next->par->GetInset(row->next->pos)
2753 && row->next->par->GetInset(row->next->pos)->display())
2755 fill_separator = w / ns;
2756 else if (direction == LYX_DIR_RIGHT_TO_LEFT)
2759 case LYX_ALIGN_RIGHT:
2762 case LYX_ALIGN_CENTER:
2770 ComputeBidiTables(row);
2771 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
2772 LyXParagraph::size_type main_body =
2773 BeginningOfMainBody(row->par);
2774 LyXParagraph::size_type last = RowLast(row);
2776 if (row->pos <= last
2778 && last != vis2log(last)
2779 && row->par->IsLineSeparator(last)) {
2780 if (!(main_body > 0 && main_body-1 == last))
2781 x -= fill_separator+SingleWidth(row->par,last);
2782 } else if (main_body > 0 &&
2783 (main_body-1 > last ||
2784 !row->par->IsLineSeparator(main_body-1))) {
2785 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
2786 row->par->GetLayout());
2787 x += GetFont(row->par, -2).stringWidth(layout.labelsep);
2788 if (main_body-1 <= last)
2789 x += fill_label_hfill;
2794 /* important for the screen */
2797 /* the cursor set functions have a special mechanism. When they
2798 * realize, that you left an empty paragraph, they will delete it.
2799 * They also delete the corresponding row */
2801 void LyXText::CursorRightOneWord() const
2803 // treat floats, HFills and Insets as words
2804 LyXCursor tmpcursor = cursor;
2806 if (tmpcursor.pos == tmpcursor.par->Last()
2807 && tmpcursor.par->Next())
2809 tmpcursor.par = tmpcursor.par->Next();
2814 // Skip through initial nonword stuff.
2815 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2816 ! tmpcursor.par->IsWord( tmpcursor.pos ) )
2818 // printf("Current pos1 %d", tmpcursor.pos) ;
2822 // Advance through word.
2823 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2824 tmpcursor.par->IsWord( tmpcursor.pos ) )
2826 // printf("Current pos2 %d", tmpcursor.pos) ;
2831 SetCursor(tmpcursor.par, tmpcursor.pos);
2835 void LyXText::CursorTab() const
2837 if (cursor.par->table) {
2838 int cell = NumberOfCell(cursor.par, cursor.pos);
2839 while(cursor.par->table->IsContRow(cell)) {
2841 cell = NumberOfCell(cursor.par, cursor.pos);
2843 if (cursor.par->table->ShouldBeVeryLastCell(cell))
2844 TableFeatures(LyXTable::APPEND_ROW);
2846 LyXCursor tmpcursor = cursor;
2847 while (tmpcursor.pos < tmpcursor.par->Last()
2848 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2851 if (tmpcursor.pos == tmpcursor.par->Last()){
2852 if (tmpcursor.par->Next()) {
2853 tmpcursor.par = tmpcursor.par->Next();
2859 SetCursor(tmpcursor.par, tmpcursor.pos);
2860 if (cursor.par->table) {
2861 int cell = NumberOfCell(cursor.par, cursor.pos);
2862 while (cursor.par->table->IsContRow(cell) &&
2863 !cursor.par->table->ShouldBeVeryLastCell(cell)) {
2865 while (tmpcursor.pos < tmpcursor.par->Last()
2866 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2869 if (tmpcursor.pos == tmpcursor.par->Last()){
2870 if (tmpcursor.par->Next()) {
2871 tmpcursor.par = tmpcursor.par->Next();
2877 SetCursor(tmpcursor.par, tmpcursor.pos);
2878 cell = NumberOfCell(cursor.par, cursor.pos);
2884 /* -------> Skip initial whitespace at end of word and move cursor to *start*
2885 of prior word, not to end of next prior word. */
2887 void LyXText::CursorLeftOneWord() const
2889 // treat HFills, floats and Insets as words
2890 LyXCursor tmpcursor = cursor;
2891 while (tmpcursor.pos
2892 && (tmpcursor.par->IsSeparator(tmpcursor.pos - 1)
2893 || tmpcursor.par->IsKomma(tmpcursor.pos - 1))
2894 && !(tmpcursor.par->IsHfill(tmpcursor.pos - 1)
2895 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2896 || tmpcursor.par->IsInset(tmpcursor.pos - 1)))
2900 && (tmpcursor.par->IsInset(tmpcursor.pos - 1)
2901 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2902 || tmpcursor.par->IsHfill(tmpcursor.pos - 1))) {
2904 } else if (!tmpcursor.pos) {
2905 if (tmpcursor.par->Previous()){
2906 tmpcursor.par = tmpcursor.par->Previous();
2907 tmpcursor.pos = tmpcursor.par->Last();
2909 } else { // Here, tmpcursor != 0
2910 while (tmpcursor.pos > 0 &&
2911 tmpcursor.par->IsWord(tmpcursor.pos-1) )
2914 SetCursor(tmpcursor.par, tmpcursor.pos);
2917 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
2920 void LyXText::SelectWord()
2922 /* Move cursor to the beginning, when not already there. */
2924 && !cursor.par->IsSeparator(cursor.pos-1)
2925 && !cursor.par->IsKomma(cursor.pos-1) )
2926 CursorLeftOneWord();
2928 /* set the sel cursor */
2929 sel_cursor = cursor;
2931 while ( cursor.pos < cursor.par->Last()
2932 && !cursor.par->IsSeparator(cursor.pos)
2933 && !cursor.par->IsKomma(cursor.pos) )
2935 SetCursor( cursor.par, cursor.pos );
2937 /* finally set the selection */
2942 /* -------> Select the word currently under the cursor when:
2943 1: no selection is currently set,
2944 2: the cursor is not at the borders of the word. */
2946 int LyXText::SelectWordWhenUnderCursor()
2948 if ( selection ) return 0;
2949 if ( cursor.pos < cursor.par->Last()
2950 && !cursor.par->IsSeparator(cursor.pos)
2951 && !cursor.par->IsKomma(cursor.pos)
2953 && !cursor.par->IsSeparator(cursor.pos -1)
2954 && !cursor.par->IsKomma(cursor.pos -1) ) {
2962 // This function is only used by the spellchecker for NextWord().
2963 // It doesn't handle LYX_ACCENTs and probably never will.
2964 char * LyXText::SelectNextWord(float & value)
2966 LyXParagraph * tmppar = cursor.par;
2968 // If this is not the very first word, skip rest of
2969 // current word because we are probably in the middle
2970 // of a word if there is text here.
2971 if (cursor.pos || cursor.par->previous) {
2972 while (cursor.pos < cursor.par->Last()
2973 && cursor.par->IsLetter(cursor.pos))
2976 // Now, skip until we have real text (will jump paragraphs)
2977 while ((cursor.par->Last() > cursor.pos
2978 && (!cursor.par->IsLetter(cursor.pos)
2979 || cursor.par->getFont(cursor.pos).latex() == LyXFont::ON))
2980 || (cursor.par->Last() == cursor.pos
2981 && cursor.par->Next())){
2982 if (cursor.pos == cursor.par->Last()) {
2983 cursor.par = cursor.par->Next();
2990 // Update the value if we changed paragraphs
2991 if (cursor.par != tmppar){
2992 SetCursor(cursor.par, cursor.pos);
2993 value = float(cursor.y)/float(height);
2996 /* Start the selection from here */
2997 sel_cursor = cursor;
3001 /* and find the end of the word
3002 (optional hyphens are part of a word) */
3003 while (cursor.pos < cursor.par->Last()
3004 && (cursor.par->IsLetter(cursor.pos))
3005 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET &&
3006 cursor.par->GetInset(cursor.pos) != 0 &&
3007 cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 &&
3011 // Finally, we copy the word to a string and return it
3014 if (sel_cursor.pos < cursor.pos) {
3015 str = new char [cursor.pos - sel_cursor.pos + 2];
3016 LyXParagraph::size_type i, j;
3017 for (i = sel_cursor.pos, j = 0; i < cursor.pos; ++i) {
3018 if (cursor.par->GetChar(i) != LyXParagraph::META_INSET)
3019 str[j++] = cursor.par->GetChar(i);
3027 // This one is also only for the spellchecker
3028 void LyXText::SelectSelectedWord()
3030 /* move cursor to the beginning */
3031 SetCursor(sel_cursor.par, sel_cursor.pos);
3033 /* set the sel cursor */
3034 sel_cursor = cursor;
3038 /* now find the end of the word */
3039 while (cursor.pos < cursor.par->Last()
3040 && (cursor.par->IsLetter(cursor.pos)
3041 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET &&
3042 cursor.par->GetInset(cursor.pos) != 0 &&
3043 cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 &&
3047 SetCursor(cursor.par, cursor.pos);
3049 /* finally set the selection */
3054 /* -------> Delete from cursor up to the end of the current or next word. */
3055 void LyXText::DeleteWordForward()
3057 LyXCursor tmpcursor = cursor;
3059 if (!cursor.par->Last())
3062 /* -------> Skip initial non-word stuff. */
3063 while ( cursor.pos < cursor.par->Last()
3064 && (cursor.par->IsSeparator(cursor.pos)
3065 || cursor.par->IsKomma(cursor.pos)) )
3068 SetCursorIntern(cursor.par, cursor.pos);
3069 selection = True; // to avoid deletion
3070 CursorRightOneWord();
3071 sel_cursor = cursor;
3075 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3081 /* -------> Delete from cursor to start of current or prior word. */
3082 void LyXText::DeleteWordBackward()
3084 LyXCursor tmpcursor = cursor;
3085 if (!cursor.par->Last())
3088 selection = true; // to avoid deletion
3089 CursorLeftOneWord();
3090 sel_cursor = cursor;
3098 /* -------> Kill to end of line. */
3099 void LyXText::DeleteLineForward()
3101 LyXCursor tmpcursor = cursor;
3102 if (!cursor.par->Last())
3106 sel_cursor = cursor;
3109 if (selection == false) {
3110 DeleteWordForward();
3118 // Change the case of a word at cursor position. The meaning of action
3120 // 0 change to lowercase
3121 // 1 capitalize word
3122 // 2 change to uppercase
3123 // This function directly manipulates LyXParagraph::text because there
3124 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3125 // that it is correct. I guess part of it should be moved to
3126 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3127 // it does not access outside of the allocated array as the older
3128 // version did. (JMarc)
3129 void LyXText::ChangeWordCase(LyXText::TextCase action)
3131 LyXParagraph * tmppar = cursor.par->ParFromPos(cursor.pos);
3133 SetUndo(Undo::FINISH, tmppar->previous, tmppar->next);
3135 LyXParagraph::size_type tmppos =
3136 cursor.par->PositionInParFromPos(cursor.pos);
3137 while (tmppos < tmppar->size()) {
3138 unsigned char c = tmppar->text[tmppos];
3139 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3141 if (c != LyXParagraph::META_INSET) {
3143 case text_lowercase:
3146 case text_capitalization:
3148 action = text_lowercase;
3150 case text_uppercase:
3156 tmppar->text[tmppos] = c;
3159 CheckParagraph(tmppar, tmppos);
3160 CursorRightOneWord();
3164 void LyXText::Delete()
3166 // this is a very easy implementation
3168 LyXCursor old_cursor = cursor;
3169 int old_cur_par_id = old_cursor.par->id();
3170 int old_cur_par_prev_id = old_cursor.par->previous ?
3171 old_cursor.par->previous->id() : 0;
3173 // just move to the right
3174 CursorRightIntern();
3176 // This check is not very good...
3177 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3178 // and that can very well delete the par or par->previous in
3179 // old_cursor. Will a solution where we compare paragraph id's
3182 if ((cursor.par->previous ? cursor.par->previous->id() : 0)
3183 == old_cur_par_prev_id
3184 && cursor.par->id() != old_cur_par_id)
3185 return; // delete-empty-paragraph-mechanism has done it
3187 if (cursor.par->previous == old_cursor.par->previous
3188 && cursor.par != old_cursor.par)
3189 return; // delete-empty-paragraph-mechanism has done it
3191 // if you had success make a backspace
3192 if (old_cursor.par != cursor.par || old_cursor.pos != cursor.pos) {
3193 LyXCursor tmpcursor = cursor;
3194 cursor = old_cursor; // to make sure undo gets the right cursor position
3195 SetUndo(Undo::DELETE,
3196 cursor.par->ParFromPos(cursor.pos)->previous,
3197 cursor.par->ParFromPos(cursor.pos)->next);
3204 void LyXText::Backspace()
3206 LyXParagraph * tmppar;
3207 Row * tmprow, * row;
3211 /* table stuff -- begin */
3212 if (cursor.par->table) {
3216 /* table stuff -- end */
3218 LyXFont rawtmpfont = current_font;
3219 LyXFont realtmpfont = real_current_font;
3221 // Get the font that is used to calculate the baselineskip
3222 int const lastpos = cursor.par->Last();
3223 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
3225 if (cursor.pos == 0) {
3226 // we may paste some paragraphs
3228 // is it an empty paragraph?
3231 || (lastpos == 1 && cursor.par->IsSeparator(0)))
3232 && !(cursor.par->Next()
3233 && cursor.par->footnoteflag ==
3234 LyXParagraph::NO_FOOTNOTE
3235 && cursor.par->Next()->footnoteflag ==
3236 LyXParagraph::OPEN_FOOTNOTE)) {
3238 if (cursor.par->previous) {
3239 tmppar = cursor.par->previous->FirstPhysicalPar();
3240 if (cursor.par->GetLayout() == tmppar->GetLayout()
3241 && cursor.par->footnoteflag == tmppar->footnoteflag
3242 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3244 tmppar->line_bottom = cursor.par->line_bottom;
3245 tmppar->added_space_bottom = cursor.par->added_space_bottom;
3246 tmppar->pagebreak_bottom = cursor.par->pagebreak_bottom;
3251 // the layout things can change the height of a row !
3252 tmpheight = cursor.row->height;
3253 SetHeightOfRow(cursor.row);
3254 if (cursor.row->height != tmpheight) {
3255 refresh_y = cursor.y - cursor.row->baseline;
3256 refresh_row = cursor.row;
3257 status = LyXText::NEED_MORE_REFRESH;
3262 if (cursor.par->ParFromPos(cursor.pos)->previous){
3263 SetUndo(Undo::DELETE,
3264 cursor.par->ParFromPos(cursor.pos)->previous->previous,
3265 cursor.par->ParFromPos(cursor.pos)->next);
3267 tmppar = cursor.par;
3268 tmprow = cursor.row;
3270 /* Pasting is not allowed, if the paragraphs have different
3271 layout. I think it is a real bug of all other
3272 word processors to allow it. It confuses the user.
3273 Even so with a footnote paragraph and a non-footnote
3274 paragraph. I will not allow pasting in this case,
3275 because the user would be confused if the footnote behaves
3276 different wether it is open or closed.
3278 Correction: Pasting is always allowed with standard-layout
3280 if (cursor.par != tmppar
3281 && (cursor.par->GetLayout() == tmppar->GetLayout()
3282 || !tmppar->GetLayout())
3283 && cursor.par->footnoteflag == tmppar->footnoteflag
3284 /* table stuff -- begin*/
3285 && !cursor.par->table /* no pasting of tables */
3286 /* table stuff -- end*/
3287 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3289 cursor.par->PasteParagraph();
3292 cursor.par->IsSeparator(cursor.pos - 1)))
3293 cursor.par->InsertChar(cursor.pos, ' ');
3298 status = LyXText::NEED_MORE_REFRESH;
3299 refresh_row = cursor.row;
3300 refresh_y = cursor.y - cursor.row->baseline;
3302 // remove the lost paragraph
3303 RemoveParagraph(tmprow);
3306 AppendParagraph(cursor.row);
3307 UpdateCounters(cursor.row);
3309 // the row may have changed, block, hfills etc.
3310 SetCursor(cursor.par, cursor.pos);
3313 /* this is the code for a normal backspace, not pasting
3315 SetUndo(Undo::DELETE,
3316 cursor.par->ParFromPos(cursor.pos)->previous,
3317 cursor.par->ParFromPos(cursor.pos)->next);
3320 // some insets are undeletable here
3321 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
3322 if (!cursor.par->GetInset(cursor.pos)->Deletable())
3324 // force complete redo when erasing display insets
3325 // this is a cruel mathod but save..... Matthias
3326 if (cursor.par->GetInset(cursor.pos)->display()){
3327 cursor.par->Erase(cursor.pos);
3334 y = cursor.y - row->baseline;
3335 LyXParagraph::size_type z;
3336 /* remember that a space at the end of a row doesnt count
3337 * when calculating the fill */
3338 if (cursor.pos < RowLast(row) ||
3339 !cursor.par->IsLineSeparator(cursor.pos)) {
3340 row->fill += SingleWidth(cursor.par, cursor.pos);
3343 /* some special code when deleting a newline. This is similar
3344 * to the behavior when pasting paragraphs */
3345 if (cursor.pos && cursor.par->IsNewline(cursor.pos)) {
3346 cursor.par->Erase(cursor.pos);
3347 // refresh the positions
3349 while (tmprow->next && tmprow->next->par == row->par) {
3350 tmprow = tmprow->next;
3353 if (cursor.par->IsLineSeparator(cursor.pos - 1))
3356 if (cursor.pos < cursor.par->Last() && !cursor.par->IsSeparator(cursor.pos)) {
3357 cursor.par->InsertChar(cursor.pos, ' ');
3358 // refresh the positions
3360 while (tmprow->next && tmprow->next->par == row->par) {
3361 tmprow = tmprow->next;
3366 cursor.par->Erase(cursor.pos);
3368 // refresh the positions
3370 while (tmprow->next && tmprow->next->par == row->par) {
3371 tmprow = tmprow->next;
3375 #ifndef FIX_DOUBLE_SPACE
3376 // delete superfluous blanks
3377 if (cursor.pos < cursor.par->Last() - 1 &&
3378 (cursor.par->IsLineSeparator(cursor.pos))) {
3380 if (cursor.pos == BeginningOfMainBody(cursor.par)
3382 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
3383 cursor.par->Erase(cursor.pos);
3384 // refresh the positions
3386 while (tmprow->next &&
3387 tmprow->next->par == row->par) {
3388 tmprow = tmprow->next;
3391 if (cursor.pos) // move one character left
3397 // delete newlines at the beginning of paragraphs
3398 while (cursor.par->Last() &&
3399 cursor.par->IsNewline(cursor.pos) &&
3400 cursor.pos == BeginningOfMainBody(cursor.par)) {
3401 cursor.par->Erase(cursor.pos);
3402 // refresh the positions
3404 while (tmprow->next &&
3405 tmprow->next->par == row->par) {
3406 tmprow = tmprow->next;
3412 // is there a break one row above
3413 if (row->previous && row->previous->par == row->par) {
3414 z = NextBreakPoint(row->previous, paperwidth);
3415 if ( z >= row->pos) {
3418 tmprow = row->previous;
3420 // maybe the current row is now empty
3421 if (row->pos >= row->par->Last()) {
3426 BreakAgainOneRow(row);
3427 if (row->next && row->next->par == row->par)
3428 need_break_row = row->next;
3433 // set the dimensions of the row above
3434 y -= tmprow->height;
3435 tmprow->fill = Fill(tmprow, paperwidth);
3436 SetHeightOfRow(tmprow);
3439 refresh_row = tmprow;
3440 status = LyXText::NEED_MORE_REFRESH;
3441 current_font = rawtmpfont;
3442 real_current_font = realtmpfont;
3443 SetCursor(cursor.par, cursor.pos, false);
3444 // check, whether the last character's font has changed.
3445 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3446 if (rawparfont != rawtmpfont)
3447 RedoHeightOfParagraph(cursor);
3452 // break the cursor row again
3453 z = NextBreakPoint(row, paperwidth);
3455 if (z != RowLast(row) ||
3456 (row->next && row->next->par == row->par &&
3457 RowLast(row) == row->par->Last() - 1)){
3459 /* it can happen that a paragraph loses one row
3460 * without a real breakup. This is when a word
3461 * is to long to be broken. Well, I don t care this
3463 if (row->next && row->next->par == row->par &&
3464 RowLast(row) == row->par->Last() - 1)
3465 RemoveRow(row->next);
3469 status = LyXText::NEED_MORE_REFRESH;
3471 BreakAgainOneRow(row);
3472 current_font = rawtmpfont;
3473 real_current_font = realtmpfont;
3474 SetCursor(cursor.par, cursor.pos, false);
3475 // cursor MUST be in row now
3477 if (row->next && row->next->par == row->par)
3478 need_break_row = row->next;
3482 // set the dimensions of the row
3483 row->fill = Fill(row, paperwidth);
3484 int tmpheight = row->height;
3485 SetHeightOfRow(row);
3486 if (tmpheight == row->height)
3487 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3489 status = LyXText::NEED_MORE_REFRESH;
3492 current_font = rawtmpfont;
3493 real_current_font = realtmpfont;
3494 SetCursor(cursor.par, cursor.pos, false);
3498 // restore the current font
3499 // That is what a user expects!
3500 current_font = rawtmpfont;
3501 real_current_font = realtmpfont;
3503 // check, wether the last characters font has changed.
3504 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3505 if (rawparfont != rawtmpfont) {
3506 RedoHeightOfParagraph(cursor);
3508 // now the special right address boxes
3509 if (textclasslist.Style(parameters->textclass,
3510 cursor.par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3511 RedoDrawingOfParagraph(cursor);
3517 void LyXText::GetVisibleRow(int offset,
3518 Row * row_ptr, long y)
3520 /* returns a printed row */
3521 Painter & pain = owner_->painter();
3523 LyXDirection direction = row_ptr->par->getParDirection();
3524 LyXParagraph::size_type vpos, pos, pos_end;
3526 int y_top, y_bottom;
3527 float fill_separator, fill_hfill, fill_label_hfill;
3528 LyXParagraph * par, * firstpar;
3531 if (row_ptr->height <= 0) {
3532 lyxerr << "LYX_ERROR: row.height: " << row_ptr->height << endl;
3535 PrepareToPrint(row_ptr, x, fill_separator,
3536 fill_hfill, fill_label_hfill);
3538 /* initialize the pixmap */
3540 pain.fillRectangle(0, offset, paperwidth, row_ptr->height);
3543 /* selection code */
3544 if (sel_start_cursor.row == row_ptr &&
3545 sel_end_cursor.row == row_ptr) {
3546 if (sel_start_cursor.x < sel_end_cursor.x)
3547 pain.fillRectangle(sel_start_cursor.x, offset,
3548 sel_end_cursor.x - sel_start_cursor.x,
3552 pain.fillRectangle(sel_end_cursor.x, offset,
3553 sel_start_cursor.x - sel_end_cursor.x,
3556 } else if (sel_start_cursor.row == row_ptr) {
3557 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3558 pain.fillRectangle(sel_start_cursor.x, offset,
3559 paperwidth - sel_start_cursor.x,
3563 pain.fillRectangle(0, offset,
3567 } else if (sel_end_cursor.row == row_ptr) {
3568 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3569 pain.fillRectangle(0, offset,
3574 pain.fillRectangle(sel_end_cursor.x, offset,
3575 paperwidth - sel_end_cursor.x,
3579 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
3580 pain.fillRectangle(0, offset,
3581 paperwidth, row_ptr->height,
3586 if (row_ptr->par->appendix){
3587 pain.line(1, offset,
3588 1, offset + row_ptr->height,
3589 LColor::appendixline);
3590 pain.line(paperwidth - 2, offset,
3591 paperwidth - 2, offset + row_ptr->height,
3592 LColor::appendixline);
3595 if (row_ptr->par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
3596 /* draw a marker at the left margin! */
3597 LyXFont font = GetFont(row_ptr->par, 0);
3598 int asc = font.maxAscent();
3599 int x = (LYX_PAPER_MARGIN - font.width('|')) / 2;
3600 int y1 = (offset + row_ptr->baseline);
3601 int y2 = (offset + row_ptr->baseline) - asc;
3602 pain.line(x, y1, x, y2, LColor::minipageline);
3604 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3605 LyXFont font(LyXFont::ALL_SANE);
3606 font.setSize(LyXFont::SIZE_FOOTNOTE);
3607 font.setColor(LColor::footnote);
3609 int box_x = LYX_PAPER_MARGIN;
3610 box_x += font.textWidth(" wide-tab ", 10);
3611 if (row_ptr->previous &&
3612 row_ptr->previous->par->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3614 switch (row_ptr->par->footnotekind) {
3615 case LyXParagraph::MARGIN:
3618 case LyXParagraph::FIG:
3621 case LyXParagraph::TAB:
3624 case LyXParagraph::WIDE_FIG:
3627 case LyXParagraph::WIDE_TAB:
3630 case LyXParagraph::ALGORITHM:
3633 case LyXParagraph::FOOTNOTE:
3638 pain.fillRectangle(LYX_PAPER_MARGIN,
3640 box_x - LYX_PAPER_MARGIN,
3641 int(font.maxAscent()
3642 + font.maxDescent()),
3643 LColor::footnotebg);
3645 pain.line(LYX_PAPER_MARGIN, offset,
3646 paperwidth - LYX_PAPER_MARGIN, offset,
3647 LColor::footnoteframe);
3649 pain.text(LYX_PAPER_MARGIN,
3650 offset + int(font.maxAscent()) + 1,
3653 pain.line(LYX_PAPER_MARGIN, offset,
3655 offset + int(font.maxAscent()
3656 + font.maxDescent()),
3657 LColor::footnoteframe);
3659 pain.line(LYX_PAPER_MARGIN,
3660 offset + int(font.maxAscent()
3661 + font.maxDescent()) + 1,
3663 offset + int(font.maxAscent()
3664 + font.maxDescent()) + 1,
3665 LColor::footnoteframe);
3669 /* draw the open floats in a red box */
3670 pain.line(box_x, offset,
3671 box_x, offset + row_ptr->height,
3672 LColor::footnoteframe);
3674 pain.line(paperwidth - LYX_PAPER_MARGIN,
3676 paperwidth - LYX_PAPER_MARGIN,
3677 offset + row_ptr->height,
3678 LColor::footnoteframe);
3679 } else if (row_ptr->previous &&
3680 row_ptr->previous->par->footnoteflag
3681 == LyXParagraph::OPEN_FOOTNOTE) {
3682 LyXFont font(LyXFont::ALL_SANE);
3683 font.setSize(LyXFont::SIZE_FOOTNOTE);
3685 int box_x = LYX_PAPER_MARGIN;
3686 box_x += font.textWidth(" wide-tab ", 10);
3688 pain.line(box_x, offset,
3689 paperwidth - LYX_PAPER_MARGIN,
3690 offset, LColor::footnote);
3693 LyXLayout const & layout =
3694 textclasslist.Style(parameters->textclass,
3695 row_ptr->par->GetLayout());
3696 firstpar = row_ptr->par->FirstPhysicalPar();
3699 y_bottom = row_ptr->height;
3701 /* is it a first row? */
3702 if (row_ptr->pos == 0
3703 && row_ptr->par == firstpar) {
3705 /* start of appendix? */
3706 if (row_ptr->par->start_of_appendix){
3707 pain.line(1, offset,
3708 paperwidth - 2, offset,
3709 LColor::appendixline);
3712 /* think about the margins */
3713 if (!row_ptr->previous)
3714 y_top += LYX_PAPER_MARGIN;
3716 if (row_ptr->par->pagebreak_top){ /* draw a top pagebreak */
3717 pain.line(0, offset + y_top + 2 * DefaultHeight(),
3719 offset + y_top + 2 * DefaultHeight(),
3720 LColor::pagebreak, Painter::line_onoffdash);
3721 y_top += 3 * DefaultHeight();
3724 if (row_ptr->par->added_space_top.kind() == VSpace::VFILL) {
3725 /* draw a vfill top */
3726 pain.line(0, offset + 2 + y_top,
3727 LYX_PAPER_MARGIN, offset + 2 + y_top,
3730 pain.line(0, offset + y_top + 3 * DefaultHeight(),
3732 offset + y_top + 3 * DefaultHeight(),
3735 pain.line(LYX_PAPER_MARGIN / 2, offset + 2 + y_top,
3736 LYX_PAPER_MARGIN / 2,
3737 offset + y_top + 3 * DefaultHeight(),
3740 y_top += 3 * DefaultHeight();
3743 /* think about user added space */
3744 y_top += int(row_ptr->par->added_space_top.inPixels());
3746 /* think about the parskip */
3747 /* some parskips VERY EASY IMPLEMENTATION */
3748 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
3749 if (layout.latextype == LATEX_PARAGRAPH
3750 && firstpar->GetDepth() == 0
3751 && firstpar->Previous())
3752 y_top += parameters->getDefSkip().inPixels();
3753 else if (firstpar->Previous()
3754 && textclasslist.Style(parameters->textclass,
3755 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
3756 && firstpar->Previous()->GetDepth() == 0)
3757 // is it right to use defskip here, too? (AS)
3758 y_top += parameters->getDefSkip().inPixels();
3761 if (row_ptr->par->line_top) { /* draw a top line */
3762 y_top += GetFont(row_ptr->par, 0).ascent('x');
3764 pain.line(0, offset + y_top,
3765 paperwidth, offset + y_top,
3767 Painter::line_solid,
3768 Painter::line_thick);
3770 y_top += GetFont(row_ptr->par, 0).ascent('x');
3773 /* should we print a label? */
3774 if (layout.labeltype >= LABEL_STATIC
3775 && (layout.labeltype != LABEL_STATIC
3776 || layout.latextype != LATEX_ENVIRONMENT
3777 || row_ptr->par->IsFirstInSequence())) {
3778 font = GetFont(row_ptr->par, -2);
3779 if (!row_ptr->par->GetLabestring().empty()) {
3781 string tmpstring = row_ptr->par->GetLabestring();
3783 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
3784 if (parameters->secnumdepth >= 0){
3785 /* this is special code for the chapter layout. This is printed in
3786 * an extra row and has a pagebreak at the top. */
3787 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue())
3788 + int(layout.parsep) * DefaultHeight();
3789 if (direction == LYX_DIR_RIGHT_TO_LEFT)
3790 tmpx = paperwidth - LeftMargin(row_ptr) -
3791 font.stringWidth(tmpstring);
3792 pain.text(int(tmpx),
3793 offset + row_ptr->baseline - row_ptr->ascent_of_text - maxdesc,
3797 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3798 tmpx = x - font.stringWidth(layout.labelsep)
3799 - font.stringWidth(tmpstring);
3801 tmpx = paperwidth - LeftMargin(row_ptr)
3802 + font.stringWidth(layout.labelsep);
3803 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3804 LyXFont font(LyXFont::ALL_SANE);
3805 font.setSize(LyXFont::SIZE_SMALL);
3806 tmpx += font.textWidth("Mwide-figM", 10);
3810 pain.text(int(tmpx),
3811 offset + row_ptr->baseline,
3815 /* the labels at the top of an environment. More or less for bibliography */
3816 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
3817 layout.labeltype == LABEL_BIBLIO ||
3818 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
3819 if (row_ptr->par->IsFirstInSequence()) {
3820 font = GetFont(row_ptr->par, -2);
3821 if (!row_ptr->par->GetLabestring().empty()) {
3822 string tmpstring = row_ptr->par->GetLabestring();
3824 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue()
3825 + (layout.labelbottomsep * DefaultHeight()));
3828 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
3829 tmpx = ( ((direction == LYX_DIR_LEFT_TO_RIGHT)
3830 ? x : LeftMargin(row_ptr) )
3831 + paperwidth - RightMargin(row_ptr) ) / 2;
3832 tmpx -= (font.stringWidth(tmpstring)/2);
3833 } else if (direction == LYX_DIR_RIGHT_TO_LEFT)
3834 tmpx = paperwidth - LeftMargin(row_ptr) -
3835 font.stringWidth(tmpstring);
3836 pain.text(int(tmpx),
3837 offset + row_ptr->baseline
3838 - row_ptr->ascent_of_text
3844 if (layout.labeltype == LABEL_BIBLIO && row_ptr->par->bibkey) {
3845 font = GetFont(row_ptr->par, -1);
3846 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3847 tmpx = x - font.stringWidth(layout.labelsep)
3848 - row_ptr->par->bibkey->width(owner_->painter(), font);
3850 tmpx = paperwidth - LeftMargin(row_ptr)
3851 + font.stringWidth(layout.labelsep);
3852 row_ptr->par->bibkey->draw(owner_->painter(),
3854 offset + row_ptr->baseline,
3859 /* is it a last row? */
3860 par = row_ptr->par->LastPhysicalPar();
3861 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
3862 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
3864 /* think about the margins */
3866 y_bottom -= LYX_PAPER_MARGIN;
3868 /* draw a bottom pagebreak */
3869 if (firstpar->pagebreak_bottom) {
3870 pain.line(0, offset + y_bottom - 2 * DefaultHeight(),
3872 offset + y_bottom - 2 * DefaultHeight(),
3873 LColor::pagebreak, Painter::line_onoffdash);
3874 y_bottom -= 3 * DefaultHeight();
3877 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
3878 /* draw a vfill bottom */
3879 pain.line(0, offset + y_bottom - 3 * DefaultHeight(),
3881 offset + y_bottom - 3 * DefaultHeight(),
3883 pain.line(0, offset + y_bottom - 2,
3885 offset + y_bottom - 2,
3887 pain.line(LYX_PAPER_MARGIN / 2,
3888 offset + y_bottom - 3 * DefaultHeight(),
3889 LYX_PAPER_MARGIN / 2,
3890 offset + y_bottom - 2,
3892 y_bottom -= 3* DefaultHeight();
3895 /* think about user added space */
3896 y_bottom -= int(firstpar->added_space_bottom.inPixels());
3898 if (firstpar->line_bottom) {
3899 /* draw a bottom line */
3900 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3901 pain.line(0, offset + y_bottom,
3902 paperwidth, offset + y_bottom,
3903 LColor::topline, Painter::line_solid,
3904 Painter::line_thick);
3905 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3909 /* draw the text in the pixmap */
3910 pos_end = RowLast(row_ptr);
3912 vpos = row_ptr->pos;
3913 /* table stuff -- begin*/
3914 if (row_ptr->par->table) {
3916 int cell = NumberOfCell(row_ptr->par, row_ptr->pos);
3918 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3920 while (vpos <= pos_end) {
3921 pos = vis2log(vpos);
3922 if (row_ptr->par->IsNewline(pos)) {
3924 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
3925 /* draw the table lines, still very simple */
3926 on_off = !row_ptr->par->table->TopLine(cell);
3928 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
3929 !row_ptr->par->table->IsContRow(cell))
3930 pain.line(int(x_old),
3931 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3933 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3935 on_off ? Painter::line_onoffdash : Painter::line_solid);
3937 on_off = !row_ptr->par->table->BottomLine(cell);
3938 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
3939 row_ptr->par->table->VeryLastRow(cell))
3941 pain.line(int(x_old),
3942 offset + y_bottom - 1,
3944 offset + y_bottom - 1,
3946 on_off ? Painter::line_onoffdash : Painter::line_solid);
3948 on_off = !row_ptr->par->table->LeftLine(cell);
3950 pain.line(int(x_old),
3951 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3953 offset + y_bottom - 1,
3955 on_off ? Painter::line_onoffdash : Painter::line_solid);
3957 on_off = !row_ptr->par->table->RightLine(cell);
3959 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
3960 offset + row_ptr->baseline - row_ptr->ascent_of_text,
3961 int(x) - row_ptr->par->table->AdditionalWidth(cell),
3962 offset + y_bottom - 1,
3964 on_off ? Painter::line_onoffdash : Painter::line_solid);
3967 /* take care about the alignment and other spaces */
3969 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3970 if (row_ptr->par->table->IsFirstCell(cell))
3971 --cell; // little hack, sorry
3973 } else if (row_ptr->par->IsHfill(pos)) {
3977 offset + row_ptr->baseline - DefaultHeight() / 2,
3979 offset + row_ptr->baseline,
3984 } else if (row_ptr->par->IsSeparator(pos)) {
3986 x+= SingleWidth(row_ptr->par, pos);
3987 /* -------> Only draw protected spaces when not in
3988 * free-spacing mode. */
3989 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
3990 pain.line(int(tmpx),
3991 offset + row_ptr->baseline - 3,
3993 offset + row_ptr->baseline - 1,
3996 pain.line(int(tmpx),
3997 offset + row_ptr->baseline - 1,
3999 offset + row_ptr->baseline - 1,
4002 pain.line(int(x - 2),
4003 offset + row_ptr->baseline - 3,
4005 offset + row_ptr->baseline - 1,
4008 /* what about underbars? */
4009 font = GetFont(row_ptr->par, pos);
4010 if (font.underbar() == LyXFont::ON
4011 && font.latex() != LyXFont::ON) {
4012 pain.line(int(tmpx),
4013 offset + row_ptr->baseline + 2,
4015 offset + row_ptr->baseline + 2);
4020 draw(row_ptr, vpos, offset, x);
4023 /* do not forget the very last cell. This has no NEWLINE so
4024 * ignored by the code above*/
4025 if (cell == row_ptr->par->table->GetNumberOfCells()-1){
4026 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
4027 on_off = !row_ptr->par->table->TopLine(cell);
4029 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
4030 !row_ptr->par->table->IsContRow(cell))
4032 pain.line(int(x_old),
4033 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4035 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4037 on_off ? Painter::line_onoffdash : Painter::line_solid);
4038 on_off = !row_ptr->par->table->BottomLine(cell);
4039 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
4040 row_ptr->par->table->VeryLastRow(cell))
4042 pain.line(int(x_old),
4043 offset + y_bottom - 1,
4045 offset + y_bottom - 1,
4047 on_off ? Painter::line_onoffdash : Painter::line_solid);
4049 on_off = !row_ptr->par->table->LeftLine(cell);
4051 pain.line(int(x_old),
4052 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4054 offset + y_bottom - 1,
4056 on_off ? Painter::line_onoffdash : Painter::line_solid);
4058 on_off = !row_ptr->par->table->RightLine(cell);
4060 pain.line(int(x) - row_ptr->par->table->AdditionalWidth(cell),
4061 offset + row_ptr->baseline - row_ptr->ascent_of_text,
4062 int(x) - row_ptr->par->table->AdditionalWidth(cell),
4063 offset + y_bottom - 1,
4065 on_off ? Painter::line_onoffdash : Painter::line_solid);
4068 /* table stuff -- end*/
4069 LyXParagraph::size_type main_body =
4070 BeginningOfMainBody(row_ptr->par);
4071 if (main_body > 0 &&
4072 (main_body-1 > pos_end ||
4073 !row_ptr->par->IsLineSeparator(main_body-1)))
4076 while (vpos <= pos_end) {
4077 pos = vis2log(vpos);
4078 if (main_body > 0 && pos == main_body-1) {
4079 x += fill_label_hfill
4080 + GetFont(row_ptr->par, -2).stringWidth(layout.labelsep)
4081 - SingleWidth(row_ptr->par, main_body-1);
4084 if (row_ptr->par->IsHfill(pos)) {
4087 offset + row_ptr->baseline - DefaultHeight() / 2,
4089 offset + row_ptr->baseline,
4092 if (HfillExpansion(row_ptr, pos)) {
4093 if (pos >= main_body) {
4095 offset + row_ptr->baseline - DefaultHeight() / 4,
4096 int(x + fill_hfill),
4097 offset + row_ptr->baseline - DefaultHeight() / 4,
4099 Painter::line_onoffdash);
4103 offset + row_ptr->baseline - DefaultHeight() / 4,
4104 int(x + fill_label_hfill),
4105 offset + row_ptr->baseline - DefaultHeight() / 4,
4107 Painter::line_onoffdash);
4109 x += fill_label_hfill;
4112 offset + row_ptr->baseline - DefaultHeight() / 2,
4114 offset + row_ptr->baseline,
4119 } else if (row_ptr->par->IsSeparator(pos)) {
4121 x+= SingleWidth(row_ptr->par, pos);
4122 if (pos >= main_body)
4124 /* -------> Only draw protected spaces when not in
4125 * free-spacing mode. */
4126 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
4128 pain.line(int(tmpx),
4129 offset + row_ptr->baseline - 3,
4131 offset + row_ptr->baseline - 1,
4134 pain.line(int(tmpx),
4135 offset + row_ptr->baseline - 1,
4137 offset + row_ptr->baseline - 1,
4140 pain.line(int(x - 2),
4141 offset + row_ptr->baseline - 3,
4143 offset + row_ptr->baseline - 1,
4146 /* what about underbars? */
4147 font = GetFont(row_ptr->par, pos);
4148 if (font.underbar() == LyXFont::ON
4149 && font.latex() != LyXFont::ON) {
4150 pain.line(int(tmpx),
4151 offset + row_ptr->baseline + 2,
4153 offset + row_ptr->baseline + 2);
4158 draw(row_ptr, vpos, offset, x);
4164 int LyXText::DefaultHeight() const
4166 LyXFont font(LyXFont::ALL_SANE);
4167 return int(font.maxAscent() + font.maxDescent() * 1.5);
4171 /* returns the column near the specified x-coordinate of the row
4172 * x is set to the real beginning of this column */
4173 int LyXText::GetColumnNearX(Row * row, int & x) const
4176 float fill_separator, fill_hfill, fill_label_hfill;
4178 PrepareToPrint(row, tmpx, fill_separator,
4179 fill_hfill, fill_label_hfill);
4181 LyXDirection direction = row->par->getParDirection();
4182 LyXParagraph::size_type vc = row->pos;
4183 LyXParagraph::size_type last = RowLast(row);
4184 LyXParagraph::size_type c;
4186 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
4187 row->par->GetLayout());
4188 /* table stuff -- begin */
4189 if (row->par->table) {
4190 if (row->next && row->next->par == row->par //the last row doesn't need a newline at the end
4191 && row->par->IsNewline(last))
4193 int cell = NumberOfCell(row->par, row->pos);
4196 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4198 && (c = vis2log(vc)) >= 0
4199 && tmpx + (SingleWidth(row->par, c)/2) <= x
4201 if (row->par->IsNewline(c)) {
4202 if (x_old + row->par->table->WidthOfColumn(cell) <= x){
4203 tmpx = x_old + row->par->table->WidthOfColumn(cell);
4206 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4211 tmpx += SingleWidth(row->par, c);
4216 /* table stuff -- end*/
4217 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
4218 float last_tmpx = tmpx;
4220 if (main_body > 0 &&
4221 (main_body-1 > last ||
4222 !row->par->IsLineSeparator(main_body-1)))
4225 while (vc <= last && tmpx <= x) {
4228 if (main_body > 0 && c == main_body-1) {
4229 tmpx += fill_label_hfill +
4230 GetFont(row->par, -2).stringWidth(layout.labelsep);
4231 if (row->par->IsLineSeparator(main_body-1))
4232 tmpx -= SingleWidth(row->par, main_body-1);
4235 tmpx += SingleWidth(row->par, c);
4236 if (HfillExpansion(row, c)) {
4240 tmpx += fill_label_hfill;
4242 else if (c >= main_body
4243 && row->par->IsSeparator(c)) {
4244 tmpx+= fill_separator;
4249 if (vc > row->pos && (tmpx+last_tmpx)/2 > x) {
4254 /* make sure that a last space in a row doesnt count */
4255 if (row->pos <= last
4256 && !(!row->next || row->next->par != row->par))
4257 if (direction == LYX_DIR_LEFT_TO_RIGHT && vc > last
4258 && row->par->IsLineSeparator(vis2log(last)) ) {
4260 tmpx -= fill_separator+SingleWidth(row->par, vis2log(last));
4261 } else if (direction == LYX_DIR_RIGHT_TO_LEFT
4263 && row->par->IsLineSeparator(vis2log(row->pos)) ) {
4265 tmpx += fill_separator+SingleWidth(row->par, vis2log(row->pos));
4268 if (row->pos > last) // Row is empty?
4270 else if (vc <= last) {
4272 LyXDirection direction = row->par->getLetterDirection(c);
4273 if (vc > row->pos && row->par->IsLineSeparator(c)
4274 && row->par->getLetterDirection(vis2log(vc - 1)) != direction)
4276 if (direction == LYX_DIR_RIGHT_TO_LEFT)
4279 c = vis2log(last)+1;
4280 if (row->par->getLetterDirection(c - 1) == LYX_DIR_RIGHT_TO_LEFT)
4284 if (!row->par->table && row->pos <= last && c > last
4285 && row->par->IsNewline(last)) {
4286 if (row->par->getLetterDirection(last) == LYX_DIR_LEFT_TO_RIGHT)
4287 tmpx -= SingleWidth(row->par, last);
4289 tmpx += SingleWidth(row->par, last);
4299 /* turn the selection into a new environment. If there is no selection,
4300 * create an empty environment */
4301 void LyXText::InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind)
4303 /* no footnoteenvironment in a footnoteenvironment */
4304 if (cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4305 WriteAlert(_("Impossible operation"),
4306 _("You can't insert a float in a float!"),
4310 /* no marginpars in minipages */
4311 if (kind == LyXParagraph::MARGIN
4312 && cursor.par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4313 WriteAlert(_("Impossible operation"),
4314 _("You can't insert a marginpar in a minipage!"),
4319 /* this doesnt make sense, if there is no selection */
4320 bool dummy_selection = false;
4322 sel_start_cursor = cursor; /* dummy selection */
4323 sel_end_cursor = cursor;
4324 dummy_selection = true;
4327 LyXParagraph *tmppar;
4329 if (sel_start_cursor.par->table || sel_end_cursor.par->table){
4330 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
4334 /* a test to make sure there is not already a footnote
4335 * in the selection. */
4337 tmppar = sel_start_cursor.par->ParFromPos(sel_start_cursor.pos);
4339 while (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos) &&
4340 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
4341 tmppar = tmppar->next;
4343 if (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)
4344 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4345 WriteAlert(_("Impossible operation"),
4346 _("Float would include float!"),
4351 /* ok we have a selection. This is always between sel_start_cursor
4352 * and sel_end cursor */
4354 SetUndo(Undo::FINISH,
4355 sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous,
4356 sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)->next);
4358 if (sel_end_cursor.pos > 0
4359 && sel_end_cursor.par->IsLineSeparator(sel_end_cursor.pos - 1))
4360 sel_end_cursor.pos--; /* please break before a space at
4362 if (sel_start_cursor.par == sel_end_cursor.par
4363 && sel_start_cursor.pos > sel_end_cursor.pos)
4364 sel_start_cursor.pos--;
4366 sel_end_cursor.par->BreakParagraphConservative(sel_end_cursor.pos);
4368 sel_end_cursor.par = sel_end_cursor.par->Next();
4369 sel_end_cursor.pos = 0;
4371 // don't forget to insert a dummy layout paragraph if necessary
4372 if (sel_start_cursor.par->GetLayout() != sel_end_cursor.par->layout){
4373 sel_end_cursor.par->BreakParagraphConservative(0);
4374 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4375 sel_end_cursor.par = sel_end_cursor.par->next;
4378 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4380 cursor = sel_end_cursor;
4382 /* please break behind a space, if there is one. The space should
4384 if (sel_start_cursor.pos > 0
4385 && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1))
4386 sel_start_cursor.pos--;
4387 if (sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) {
4388 sel_start_cursor.par->Erase(sel_start_cursor.pos);
4391 sel_start_cursor.par->BreakParagraphConservative(sel_start_cursor.pos);
4392 tmppar = sel_start_cursor.par->Next();
4394 if (dummy_selection) {
4396 if (kind == LyXParagraph::TAB
4397 || kind == LyXParagraph::FIG
4398 || kind == LyXParagraph::WIDE_TAB
4399 || kind == LyXParagraph::WIDE_FIG
4400 || kind == LyXParagraph::ALGORITHM) {
4401 int lay = textclasslist.NumberOfLayout(parameters->textclass,
4403 if (lay == -1) // layout not found
4404 // use default layout "Standard" (0)
4406 tmppar->SetLayout(lay);
4410 if (sel_start_cursor.pos > 0) {
4411 /* the footnote-environment should begin with a standard layout.
4412 * Imagine you insert a footnote within an enumeration, you
4413 * certainly do not want an enumerated footnote! */
4417 /* this is a exception the user would sometimes expect, I hope */
4418 sel_start_cursor.par->Clear();
4422 while (tmppar != sel_end_cursor.par) {
4423 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4424 tmppar->footnotekind = kind;
4425 tmppar = tmppar->Next();
4428 RedoParagraphs(sel_start_cursor, sel_end_cursor.par->Next());
4430 SetCursor(sel_start_cursor.par->Next(), 0);
4436 // returns pointer to a specified row
4437 Row * LyXText::GetRow(LyXParagraph * par,
4438 LyXParagraph::size_type pos, long & y) const
4443 if (par == currentrow->par || par == currentrow->par->Previous()) {
4444 // do not dereference par, it may have been deleted
4445 // already! (Matthias)
4446 while (currentrow->previous && currentrow->previous->par != par) {
4447 currentrow = currentrow->previous;
4448 currentrow_y -= currentrow->height;
4450 while (currentrow->previous && currentrow->previous->par == par) {
4451 currentrow = currentrow->previous;
4452 currentrow_y -= currentrow->height;
4455 tmprow = currentrow;
4457 // find the first row of the specified paragraph
4458 while (tmprow->next && (tmprow->par != par)) {
4459 y += tmprow->height;
4460 tmprow = tmprow->next;
4463 if (tmprow->par == par){
4464 // now find the wanted row
4465 while (tmprow->pos < pos && tmprow->next && tmprow->next->par == par &&
4466 tmprow->next->pos <= pos) {
4467 y += tmprow->height;
4468 tmprow = tmprow->next;
4470 currentrow = tmprow;
4477 // find the first row of the specified paragraph
4478 while (tmprow->next && (tmprow->par != par)) {
4479 y += tmprow->height;
4480 tmprow = tmprow->next;
4483 // now find the wanted row
4484 while (tmprow->pos < pos && tmprow->next && tmprow->next->par == par &&
4485 tmprow->next->pos <= pos) {
4486 y += tmprow->height;
4487 tmprow = tmprow->next;
4490 currentrow = tmprow;