1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * ====================================================== */
16 #pragma implementation "table.h"
20 #include "lyxparagraph.h"
22 #include "support/textutils.h"
23 #include "lyx_gui_misc.h"
26 #include "bufferparams.h"
28 #include "lyxscreen.h"
29 #include "minibuffer.h"
37 static const int LYX_PAPER_MARGIN = 20;
39 extern int mono_video;
40 extern int reverse_video;
41 extern int fast_selection;
42 extern BufferView * current_view;
46 extern int bibitemMaxWidth(LyXFont const &);
48 #define FIX_DOUBLE_SPACE 1
50 int LyXText::SingleWidth(LyXParagraph * par,
51 LyXParagraph::size_type pos) const
53 char c = par->GetChar(pos);
54 return SingleWidth(par, pos, c);
58 int LyXText::SingleWidth(LyXParagraph * par,
59 LyXParagraph::size_type pos, char c) const
61 LyXFont font = GetFont(par, pos);
63 // The most common case is handled first (Asger)
67 } else if (IsHfillChar(c)) {
68 return 3; /* Because of the representation
69 * as vertical lines */
71 } else if (c == LyXParagraph::META_FOOTNOTE ||
72 c == LyXParagraph::META_MARGIN ||
73 c == LyXParagraph::META_FIG ||
74 c == LyXParagraph::META_TAB ||
75 c == LyXParagraph::META_WIDE_FIG ||
76 c == LyXParagraph::META_WIDE_TAB ||
77 c == LyXParagraph::META_ALGORITHM)
81 case LyXParagraph::META_MARGIN:
84 case LyXParagraph::META_FIG:
87 case LyXParagraph::META_TAB:
90 case LyXParagraph::META_ALGORITHM:
93 case LyXParagraph::META_WIDE_FIG:
96 case LyXParagraph::META_WIDE_TAB:
99 case LyXParagraph::META_FOOTNOTE:
105 return font.stringWidth(fs);
108 else if (c == LyXParagraph::META_INSET) {
109 Inset *tmpinset= par->GetInset(pos);
111 return par->GetInset(pos)->Width(font);
115 } else if (IsSeparatorChar(c))
117 else if (IsNewlineChar(c))
119 return font.width(c);
123 // Returns the paragraph position of the last character in the specified row
124 LyXParagraph::size_type LyXText::RowLast(Row const * row) const
127 return row->par->Last() - 1;
128 else if (row->next->par != row->par)
129 return row->par->Last() - 1;
131 return row->next->pos - 1;
134 LyXDirection LyXText::GetDocumentDirection() const {
135 return (lyxrc->rtl_support && parameters->language == "hebrew")
136 ? LYX_DIR_RIGHT_TO_LEFT : LYX_DIR_LEFT_TO_RIGHT;
139 LyXDirection LyXText::GetParDirection(LyXParagraph * par) const {
140 if (!lyxrc->rtl_support || par->table)
141 return LYX_DIR_LEFT_TO_RIGHT;
144 return (GetFont(par, 0).direction() == LyXFont::RTL_DIR)
145 ? LYX_DIR_RIGHT_TO_LEFT : LYX_DIR_LEFT_TO_RIGHT;
147 return GetDocumentDirection();
150 LyXDirection LyXText::GetFontDirection(LyXFont const &font) const {
151 if (lyxrc->rtl_support
152 && font.direction() == LyXFont::RTL_DIR
153 && font.latex() != LyXFont::ON)
154 return LYX_DIR_RIGHT_TO_LEFT;
156 return LYX_DIR_LEFT_TO_RIGHT;
159 LyXDirection LyXText::GetLetterDirection(LyXParagraph * par,
160 LyXParagraph::size_type pos) const {
161 if (!lyxrc->rtl_support)
162 return LYX_DIR_LEFT_TO_RIGHT;
164 LyXDirection direction = GetFontDirection(GetFont(par, pos));
165 if (par->IsLineSeparator(pos) && 0 < pos && pos < par->Last()-1
166 && !par->IsLineSeparator(pos+1)
167 && !(par->table && par->IsNewline(pos+1))
168 && ( GetFontDirection(GetFont(par, pos-1)) != direction ||
169 GetFontDirection(GetFont(par, pos+1)) != direction) )
170 return GetParDirection(par);
175 void LyXText::ComputeBidiTables(Row *row) const {
177 if (!lyxrc->rtl_support) {
181 LyXParagraph::size_type last = RowLast(row);
182 bidi_start = row->pos;
184 if (bidi_start > last) {
189 if (last+2-bidi_start >
190 static_cast<LyXParagraph::size_type>(log2vis_list.size()) ) {
191 LyXParagraph::size_type new_size =
192 (last+2-bidi_start < 500) ? 500 : 2*(last+2-bidi_start);
193 log2vis_list.resize(new_size);
194 vis2log_list.resize(new_size);
197 vis2log_list[last+1-bidi_start] = -1;
198 log2vis_list[last+1-bidi_start] = -1;
200 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
201 if (main_body > 0 && row->pos < main_body-1 && main_body-1 <= last
202 && row->par->IsLineSeparator(main_body-1)) {
203 // This is needed in case there is a direction change in
204 // the label which is continued into the main body
205 if (GetParDirection(row->par) == LYX_DIR_LEFT_TO_RIGHT) {
206 ComputeBidiTablesFromTo(row,bidi_start,main_body-2,0);
207 log2vis_list[main_body-1-bidi_start] = main_body-1;
208 vis2log_list[main_body-1-bidi_start] = main_body-1;
209 if (main_body <= last)
210 ComputeBidiTablesFromTo(row,main_body,last,0);
212 ComputeBidiTablesFromTo(row,bidi_start,main_body-2,last-main_body+2);
213 log2vis_list[main_body-1-bidi_start] = last-main_body+1+bidi_start;
214 vis2log_list[last-main_body+1-bidi_start] = main_body-1;
215 if (main_body <= last)
216 ComputeBidiTablesFromTo(row,main_body,last,-main_body);
219 ComputeBidiTablesFromTo(row,bidi_start,last,0);
223 void LyXText::ComputeBidiTablesFromTo(Row *row,
224 LyXParagraph::size_type from,
225 LyXParagraph::size_type to,
226 LyXParagraph::size_type offset) const {
228 LyXParagraph::size_type vpos, old_lpos, stack[2];
229 LyXDirection par_direction = GetParDirection(row->par);
230 LyXDirection direction = par_direction;
231 LyXParagraph::size_type lpos = from;
235 if (GetLetterDirection(row->par, lpos) == direction) {
236 log2vis_list[lpos-bidi_start] = direction;
240 (level == 1 && direction == LYX_DIR_RIGHT_TO_LEFT
241 && GetFont(row->par, lpos).direction() == LyXFont::RTL_DIR
242 && GetFont(row->par, lpos).latex() == LyXFont::ON ) ) {
243 // The last check is needed when the char is a space
244 stack[level++] = lpos;
246 old_lpos = stack[--level];
247 log2vis_list[old_lpos-bidi_start] =
248 log2vis_list[lpos-bidi_start] =
249 (old_lpos-lpos)*direction;
252 direction = static_cast<LyXDirection>(-direction);
257 old_lpos = stack[--level];
258 log2vis_list[old_lpos-bidi_start] = (old_lpos-(to+1))*direction;
259 direction = static_cast<LyXDirection>(-direction);
262 vpos = (par_direction == LYX_DIR_LEFT_TO_RIGHT)
265 for (lpos = from; lpos <= to; lpos++) {
266 vpos += log2vis_list[lpos-bidi_start];
267 vis2log_list[vpos-bidi_start] = lpos;
268 log2vis_list[lpos-bidi_start] = vpos;
272 void LyXText::Draw(Row const * row, LyXParagraph::size_type & vpos,
273 LyXScreen & scr, int offset, float & x)
275 LyXParagraph::size_type pos = vis2log(vpos);
276 char c = row->par->GetChar(pos);
278 if (IsNewlineChar(c)) {
280 // Draw end-of-line marker
282 LyXFont font = GetFont(row->par, pos);
283 int asc = font.maxAscent();
284 int wid = font.width('n');
285 int y = (offset + row->baseline);
287 if (GetLetterDirection(row->par, pos) == LYX_DIR_LEFT_TO_RIGHT) {
288 p[0].x = int(x + wid*0.375); p[0].y = int(y - 0.875*asc*0.75);
289 p[1].x = int(x); p[1].y = int(y - 0.500*asc*0.75);
290 p[2].x = int(x + wid*0.375); p[2].y = int(y - 0.125*asc*0.75);
291 scr.drawLines(::getGC(gc_new_line), p, 3);
293 p[0].x = int(x); p[0].y = int(y - 0.500*asc*0.75);
294 p[1].x = int(x + wid); p[1].y = int(y - 0.500*asc*0.75);
295 p[2].x = int(x + wid); p[2].y = int(y - asc*0.75);
296 scr.drawLines(::getGC(gc_new_line), p, 3);
298 p[0].x = int(x + wid*0.625); p[0].y = int(y - 0.875*asc*0.75);
299 p[1].x = int(x + wid); p[1].y = int(y - 0.500*asc*0.75);
300 p[2].x = int(x + wid*0.625); p[2].y = int(y - 0.125*asc*0.75);
301 scr.drawLines(::getGC(gc_new_line), p, 3);
303 p[0].x = int(x + wid); p[0].y = int(y - 0.500*asc*0.75);
304 p[1].x = int(x); p[1].y = int(y - 0.500*asc*0.75);
305 p[2].x = int(x); p[2].y = int(y - asc*0.75);
306 scr.drawLines(::getGC(gc_new_line), p, 3);
312 LyXFont font = GetFont(row->par, pos);
313 LyXFont font2 = font;
315 if (c == LyXParagraph::META_FOOTNOTE
316 || c == LyXParagraph::META_MARGIN
317 || c == LyXParagraph::META_FIG
318 || c == LyXParagraph::META_TAB
319 || c == LyXParagraph::META_WIDE_FIG
320 || c == LyXParagraph::META_WIDE_TAB
321 || c == LyXParagraph::META_ALGORITHM) {
324 case LyXParagraph::META_MARGIN:
326 // Draw a sign at the left margin!
327 scr.drawText(font, "!", 1, offset + row->baseline,
328 (LYX_PAPER_MARGIN - font.width('!'))/2);
330 case LyXParagraph::META_FIG:
333 case LyXParagraph::META_TAB:
336 case LyXParagraph::META_ALGORITHM:
339 case LyXParagraph::META_WIDE_FIG:
342 case LyXParagraph::META_WIDE_TAB:
345 case LyXParagraph::META_FOOTNOTE:
352 // calculate the position of the footnotemark
353 int y = (row->baseline - font2.maxAscent()
356 font.setColor(LyXFont::INSET);
360 // draw it and set new x position
361 x += scr.drawString(font, fs, offset + y, int(x));
363 scr.drawLine(gc_foot, offset + row->baseline,
364 int(tmpx), int(x - tmpx));
368 } else if (c == LyXParagraph::META_INSET) {
369 Inset * tmpinset = row->par->GetInset(pos);
371 tmpinset->Draw(font, scr, offset + row->baseline, x);
376 /* usual characters, no insets */
378 // Collect character that we can draw in one command
380 // This is dirty, but fast. Notice that it will never be too small.
381 // For the record, I'll note that Microsoft Word has a limit
382 // of 768 here. We have none :-) (Asger)
383 // Ok. I am the first to admit that the use of std::string will be
384 // a tiny bit slower than using a POD char array. However, I claim
385 // that this slowdown is so small that it is close to inperceptive.
386 // So IMHO we should go with the easier and clearer implementation.
387 // And even if 1024 is a large number here it might overflow, string
388 // will only overflow if the machine is out of memory...
389 static string textstring;
393 LyXParagraph::size_type last = RowLast(row);
395 while (vpos <= last &&
396 (pos = vis2log(vpos)) >= 0
397 && static_cast<unsigned char>(c = row->par->GetChar(pos)) > ' '
398 && font2 == GetFont(row->par, pos)) {
404 // If monochrome and LaTeX mode, provide reverse background
406 font.latex() == LyXFont::ON) {
407 int a = font.maxAscent();
408 int d = font.maxDescent();
409 scr.fillRectangle(gc_copy, int(tmpx),
410 offset + row->baseline - a,
411 font.textWidth(textstring.c_str(),
412 textstring.length()), a + d);
415 // Draw text and set the new x position
416 x += scr.drawText(font, textstring.c_str(), textstring.length(),
417 offset + row->baseline,
420 // what about underbars?
421 if (font.underbar() == LyXFont::ON && font.latex() != LyXFont::ON) {
422 scr.drawLine(gc_copy, offset + row->baseline + 2,
423 int(tmpx), int(x - tmpx));
426 // If we want ulem.sty support, drawing
427 // routines should go here. (Asger)
428 // Why shouldn't LyXFont::drawText handle it internally?
432 // Returns the left beginning of the text.
433 // This information cannot be taken from the layouts-objekt, because in
434 // LaTeX the beginning of the text fits in some cases (for example sections)
435 // exactly the label-width.
436 int LyXText::LeftMargin(Row const * row) const
438 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
439 row->par->GetLayout());
441 string parindent = layout.parindent;
443 /* table stuff -- begin */
446 /* table stuff -- end */
448 int x = LYX_PAPER_MARGIN;
450 x += textclasslist.TextClass(parameters->textclass)
452 .signedStringWidth(textclasslist
453 .TextClass(parameters->textclass)
456 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
457 LyXFont font(LyXFont::ALL_SANE);
458 font.setSize(LyXFont::SIZE_SMALL);
459 x += font.textWidth("Mwide-figM", 10) + LYX_PAPER_MARGIN/2;
462 // this is the way, LyX handles the LaTeX-Environments.
463 // I have had this idea very late, so it seems to be a
464 // later added hack and this is true
465 if (!row->par->GetDepth()) {
466 if (!row->par->GetLayout()) {
467 // find the previous same level paragraph
468 if (row->par->FirstPhysicalPar()->Previous()) {
469 LyXParagraph * newpar = row->par
470 ->DepthHook(row->par->GetDepth());
472 textclasslist.Style(parameters->textclass,
479 // find the next level paragraph
481 LyXParagraph * newpar = row->par->DepthHook(row->par->GetDepth()-1);
483 // make a corresponding row. Needed to call LeftMargin()
485 // check wether it is a sufficent paragraph
486 if (newpar && newpar->footnoteflag == row->par->footnoteflag
488 .Style(parameters->textclass,
489 newpar->GetLayout()).isEnvironment()) {
491 dummyrow.par = newpar;
492 dummyrow.pos = newpar->Last();
493 x = LeftMargin(&dummyrow);
495 // this is no longer an error, because this function
496 // is used to clear impossible depths after changing
497 // a layout. Since there is always a redo,
498 // LeftMargin() is always called
499 row->par->FirstPhysicalPar()->depth = 0;
502 if (newpar && !row->par->GetLayout()) {
503 if (newpar->FirstPhysicalPar()->noindent)
506 parindent = textclasslist
507 .Style(parameters->textclass,
508 newpar->GetLayout()).parindent;
513 LyXFont labelfont = GetFont(row->par, -2);
514 switch (layout.margintype) {
516 if (!layout.leftmargin.empty()) {
518 .TextClass(parameters->textclass)
520 .signedStringWidth(layout.leftmargin);
522 if (!row->par->GetLabestring().empty()) {
523 x += labelfont.signedStringWidth(layout.labelindent);
524 x += labelfont.stringWidth(row->par->GetLabestring());
525 x += labelfont.stringWidth(layout.labelsep);
529 x += labelfont.signedStringWidth(layout.labelindent);
530 if (row->pos >= BeginningOfMainBody(row->par)) {
531 if (!row->par->GetLabelWidthString().empty()) {
533 .stringWidth(row->par
534 ->GetLabelWidthString());
535 x += labelfont.stringWidth(layout.labelsep);
540 x += textclasslist.TextClass(parameters->textclass)
541 .defaultfont().signedStringWidth(layout.leftmargin) * 4
542 / (row->par->GetDepth() + 4);
544 case MARGIN_FIRST_DYNAMIC:
545 if (layout.labeltype == LABEL_MANUAL) {
546 if (row->pos >= BeginningOfMainBody(row->par)) {
548 .signedStringWidth(layout.leftmargin);
551 .signedStringWidth(layout.labelindent);
554 // Special case to fix problems with
556 || (layout.labeltype == LABEL_STATIC
557 && layout.latextype == LATEX_ENVIRONMENT
558 && ! row->par->IsFirstInSequence())) {
559 x += labelfont.signedStringWidth(layout.leftmargin);
560 } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
561 && layout.labeltype != LABEL_BIBLIO
562 && layout.labeltype !=
563 LABEL_CENTERED_TOP_ENVIRONMENT) {
564 x += labelfont.signedStringWidth(layout.labelindent);
565 x += labelfont.stringWidth(layout.labelsep);
566 x += labelfont.stringWidth(row->par->GetLabestring());
570 case MARGIN_RIGHT_ADDRESS_BOX:
572 // ok, a terrible hack. The left margin depends on the widest
573 // row in this paragraph. Do not care about footnotes, they
574 // are *NOT* allowed in the LaTeX realisation of this layout.
576 // find the first row of this paragraph
577 Row const * tmprow = row;
578 while (tmprow->previous && tmprow->previous->par == row->par)
579 tmprow = tmprow->previous;
581 int minfill = tmprow->fill;
582 while (tmprow->next && tmprow->next->par == row->par) {
583 tmprow = tmprow->next;
584 if (tmprow->fill < minfill)
585 minfill = tmprow->fill;
588 x += textclasslist.TextClass(parameters->textclass)
589 .defaultfont().signedStringWidth(layout.leftmargin);
594 if (row->par->pextra_type == LyXParagraph::PEXTRA_INDENT) {
595 if (!row->par->pextra_widthp.empty()) {
597 atoi(row->par->pextra_widthp.c_str()) / 100;
598 } else if (!row->par->pextra_width.empty()) {
599 int xx = VSpace(row->par->pextra_width).inPixels();
602 xx = paperwidth * 80 / 100;
604 } else { // should not happen
605 LyXFont font(LyXFont::ALL_SANE);
606 x += font.stringWidth("XXXXXX");
611 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
612 align = layout.align;
614 align = row->par->FirstPhysicalPar()->align;
616 // set the correct parindent
618 if ((layout.labeltype == LABEL_NO_LABEL
619 || layout.labeltype == LABEL_TOP_ENVIRONMENT
620 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
621 || (layout.labeltype == LABEL_STATIC
622 && layout.latextype == LATEX_ENVIRONMENT
623 && ! row->par->IsFirstInSequence()))
624 && row->par == row->par->FirstPhysicalPar()
625 && align == LYX_ALIGN_BLOCK
626 && !row->par->noindent
627 && (row->par->layout ||
628 parameters->paragraph_separation ==
629 BufferParams::PARSEP_INDENT))
630 x += textclasslist.TextClass(parameters->textclass)
631 .defaultfont().stringWidth(parindent);
633 if (layout.labeltype == LABEL_BIBLIO) {
634 // ale970405 Right width for bibitems
635 x += bibitemMaxWidth(textclasslist
636 .TextClass(parameters
646 int LyXText::RightMargin(Row const * row) const
648 LyXLayout const & layout =
649 textclasslist.Style(parameters->textclass,
650 row->par->GetLayout());
652 int x = LYX_PAPER_MARGIN
654 .TextClass(parameters->textclass)
656 .signedStringWidth(textclasslist
657 .TextClass(parameters->textclass)
660 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
661 x += LYX_PAPER_MARGIN / 2;
664 // this is the way, LyX handles the LaTeX-Environments.
665 // I have had this idea very late, so it seems to be a
666 // later added hack and this is true
667 if (row->par->GetDepth()) {
668 // find the next level paragraph
670 LyXParagraph * newpar = row->par;
673 newpar = newpar->FirstPhysicalPar()->Previous();
675 newpar = newpar->FirstPhysicalPar();
676 } while (newpar && newpar->GetDepth() >= row->par->GetDepth()
677 && newpar->footnoteflag == row->par->footnoteflag);
679 // make a corresponding row. Needed to call LeftMargin()
681 // check wether it is a sufficent paragraph
682 if (newpar && newpar->footnoteflag == row->par->footnoteflag
683 && textclasslist.Style(parameters->textclass,
687 dummyrow.par = newpar;
689 x = RightMargin(&dummyrow);
691 // this is no longer an error, because this function
692 // is used to clear impossible depths after changing
693 // a layout. Since there is always a redo,
694 // LeftMargin() is always called
695 row->par->FirstPhysicalPar()->depth = 0;
699 //lyxerr << "rightmargin: " << layout->rightmargin << endl;
700 x += textclasslist.TextClass(parameters->textclass)
702 .signedStringWidth(layout.rightmargin) * 4
703 / (row->par->GetDepth() + 4);
708 int LyXText::LabelEnd (Row const * row) const
710 if (textclasslist.Style(parameters->textclass,
711 row->par->GetLayout()).margintype
715 tmprow.pos = row->par->Last();
716 return LeftMargin(&tmprow); /* just the beginning
719 return 0; /* LabelEnd is only needed, if the
720 layout fills a flushleft
725 /* table stuff -- begin*/
726 int LyXText::NumberOfCell(LyXParagraph * par,
727 LyXParagraph::size_type pos) const
730 LyXParagraph::size_type tmp_pos = 0;
731 while (tmp_pos < pos) {
732 if (par->IsNewline(tmp_pos))
740 int LyXText::WidthOfCell(LyXParagraph * par,
741 LyXParagraph::size_type & pos) const
744 while (pos < par->Last() && !par->IsNewline(pos)) {
745 w += SingleWidth(par, pos);
748 if (par->IsNewline(pos))
754 bool LyXText::HitInTable(Row * row, int x) const
757 float fill_separator, fill_hfill, fill_label_hfill;
758 if (!row->par->table)
760 PrepareToPrint(row, tmpx, fill_separator,
761 fill_hfill, fill_label_hfill, false);
762 return (x > tmpx && x < tmpx + row->par->table->WidthOfTable());
766 bool LyXText::MouseHitInTable(int x, long y) const
768 Row * row = GetRowNearY(y);
769 return HitInTable(row, x);
773 /* table stuff -- end*/
776 // get the next breakpoint in a given paragraph
777 LyXParagraph::size_type
778 LyXText::NextBreakPoint(Row const * row, int width) const
780 LyXParagraph * par = row->par;
781 LyXParagraph::size_type pos = row->pos;
783 /* table stuff -- begin*/
785 while (pos < par->size()
786 && (!par->IsNewline(pos)
787 || !par->table->IsFirstCell(NumberOfCell(par, pos+1)))) {
788 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
789 par->GetInset(pos) && par->GetInset(pos)->display()){
790 par->GetInset(pos)->display(false);
796 /* table stuff -- end*/
798 // position of the last possible breakpoint
799 // -1 isn't a suitable value, but a flag
800 LyXParagraph::size_type last_separator = -1;
801 int left_margin = LabelEnd(row);
802 width -= RightMargin(row);
804 LyXParagraph::size_type main_body = BeginningOfMainBody(par);
805 LyXLayout const & layout =
806 textclasslist.Style(parameters->textclass, par->GetLayout());
807 LyXParagraph::size_type i = pos;
809 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
810 /* special code for right address boxes, only newlines count */
811 while (i < par->Last()) {
812 if (par->IsNewline(i)) {
814 i = par->Last() - 1; // this means break
816 } else if (par->GetChar(i) == LyXParagraph::META_INSET &&
817 par->GetInset(i) && par->GetInset(i)->display()){
818 par->GetInset(i)->display(false);
823 // Last position is an invariant
824 LyXParagraph::size_type const last =
826 // this is the usual handling
827 int x = LeftMargin(row);
828 while (x < width && i < last) {
829 char c = par->GetChar(i);
830 if (IsNewlineChar(c)) {
832 x = width; // this means break
833 } else if (c == LyXParagraph::META_INSET &&
834 par->GetInset(i) && par->GetInset(i)->display()){
835 // check wether a Display() inset is
836 // valid here. if not, change it to
838 if (layout.isCommand()
839 || (layout.labeltype == LABEL_MANUAL
840 && i < BeginningOfMainBody(par))){
841 // display istn't allowd
842 par->GetInset(i)->display(false);
843 x += SingleWidth(par, i, c);
845 // inset is display. So break the line here
849 if (IsLineSeparatorChar(par->GetChar(i+1)))
852 last_separator = last; // to avoid extra rows
854 last_separator = i - 1;
855 x = width; // this means break
858 if (IsLineSeparatorChar(c))
860 x += SingleWidth(par, i, c);
863 if (i == main_body) {
864 x += GetFont(par, -2).stringWidth(layout.labelsep);
865 if (par->IsLineSeparator(i - 1))
866 x-= SingleWidth(par, i - 1);
871 // end of paragraph is always a suitable separator
872 if (i == last && x < width)
876 // well, if last_separator is still 0, the line isn't breakable.
877 // don't care and cut simply at the end
878 if (last_separator < 0) {
882 // manual labels cannot be broken in LaTeX, do not care
883 if (main_body && last_separator < main_body)
884 last_separator = main_body - 1;
886 return last_separator;
890 // returns the minimum space a row needs on the screen in pixel
891 int LyXText::Fill(Row const * row, int paper_width) const
894 // get the pure distance
895 LyXParagraph::size_type last = RowLast(row);
896 /* table stuff -- begin */
897 if (row->par->table) {
898 // for tables FILL does calculate the widthes of each cell in
900 LyXParagraph::size_type pos = row->pos;
901 int cell = NumberOfCell(row->par, pos);
904 row->par->table->SetWidthOfCell(cell,
905 WidthOfCell(row->par,
908 } while (pos <= last && !row->par->table->IsFirstCell(cell));
909 // don't forget the very last table cell without characters
910 if (cell == row->par->table->GetNumberOfCells() - 1)
911 row->par->table->SetWidthOfCell(cell,
912 WidthOfCell(row->par,
915 return 0; /* width of table cannot be returned since
916 * we cannot guarantee its correct value at
919 /* table stuff -- end*/
921 int left_margin = LabelEnd(row);
923 // if the row ends with newline, this newline will not be relevant
924 //if (last >= 0 && row->par->IsNewline(last))
927 // if the row ends with a space, this space will not be relevant
928 if (last >= 0 && row->par->IsLineSeparator(last))
931 // special handling of the right address boxes
932 if (textclasslist.Style(parameters->textclass,
933 row->par->GetLayout()).margintype
934 == MARGIN_RIGHT_ADDRESS_BOX) {
935 int tmpfill = row->fill;
936 row->fill = 0; // the minfill in MarginLeft()
942 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
943 row->par->GetLayout());
944 LyXParagraph::size_type main_body =
945 BeginningOfMainBody(row->par);
946 LyXParagraph::size_type i = row->pos;
949 if (main_body > 0 && i == main_body) {
950 w += GetFont(row->par, -2).
951 stringWidth(layout.labelsep);
952 if (row->par->IsLineSeparator(i - 1))
953 w -= SingleWidth(row->par, i - 1);
957 w += SingleWidth(row->par, i);
960 if (main_body > 0 && main_body > last) {
961 w += GetFont(row->par, -2).stringWidth(layout.labelsep);
962 if (last >= 0 && row->par->IsLineSeparator(last))
963 w -= SingleWidth(row->par, last);
968 fill = paper_width - w - RightMargin(row);
973 // returns the minimum space a manual label needs on the screen in pixel
974 int LyXText::LabelFill(Row const * row) const
976 LyXParagraph::size_type last = BeginningOfMainBody(row->par) - 1;
977 // -1 because a label ends either with a space that is in the label,
978 // or with the beginning of a footnote that is outside the label.
980 // I don't understand this code in depth, but sometimes "last" is
981 // less than 0 and this causes a crash. This fix seems to work
982 // correctly, but I bet the real error is elsewhere. The bug is
983 // triggered when you have an open footnote in a paragraph
984 // environment with a manual label. (Asger)
985 if (last < 0) last = 0;
987 if (row->par->IsLineSeparator(last)) /* a sepearator at this end
994 w += SingleWidth(row->par, i);
999 if (!row->par->labelwidthstring.empty()) {
1000 fill = GetFont(row->par, -2)
1001 .stringWidth(row->par->labelwidthstring) - w;
1011 // returns the number of separators in the specified row. The separator
1012 // on the very last column doesnt count
1013 int LyXText::NumberOfSeparators(Row const * row) const
1015 int last = RowLast(row);
1017 //int main_body = BeginningOfMainBody(row->par);
1018 //if (p < main_body)
1020 // I think this is equivalent to the above. (Lgb)
1021 int p = max(row->pos, BeginningOfMainBody(row->par));
1023 for (; p < last; ++p) {
1024 if (row->par->IsSeparator(p)) {
1032 // returns the number of hfills in the specified row. The LyX-Hfill is
1033 // a LaTeX \hfill so that the hfills at the beginning and at the end were
1034 // ignored. This is *MUCH* more usefull than not to ignore!
1035 int LyXText::NumberOfHfills(Row const * row) const
1037 int last = RowLast(row);
1038 int first = row->pos;
1039 if (first) { /* hfill *DO* count at the beginning
1041 while(first <= last && row->par->IsHfill(first))
1045 //int main_body = BeginningOfMainBody(row->par);
1046 //if (first < main_body)
1047 // first = main_body;
1048 // I think this is equivalent to the above. (Lgb)
1049 first = max(first, BeginningOfMainBody(row->par));
1051 for (int p = first; p <= last; ++p) { // last, because the end is ignored!
1052 if (row->par->IsHfill(p)) {
1060 // like NumberOfHfills, but only those in the manual label!
1061 int LyXText::NumberOfLabelHfills(Row const * row) const
1063 LyXParagraph::size_type last = RowLast(row);
1064 LyXParagraph::size_type first = row->pos;
1065 if (first) { /* hfill *DO* count at the beginning
1067 while(first < last && row->par->IsHfill(first))
1070 //LyXParagraph::size_type main_body =
1071 //BeginningOfMainBody(row->par);
1072 //if (last > main_body)
1074 // I think this is eqvialent to the above. (Lgb)
1075 last = min(last, BeginningOfMainBody(row->par));
1077 for (LyXParagraph::size_type p = first;
1078 p < last; ++p) { // last, because the end is ignored!
1079 if (row->par->IsHfill(p)) {
1087 // returns true, if a expansion is needed.
1088 // Rules are given by LaTeX
1089 bool LyXText::HfillExpansion(Row const * row_ptr,
1090 LyXParagraph::size_type pos) const
1092 // by the way, is it a hfill?
1093 if (!row_ptr->par->IsHfill(pos))
1096 // at the end of a row it does not count
1097 if (pos >= RowLast(row_ptr))
1100 // at the beginning of a row it does not count, if it is not
1101 // the first row of a paragaph
1105 // in some labels it does not count
1106 if (textclasslist.Style(parameters->textclass,
1107 row_ptr->par->GetLayout()).margintype
1109 && pos < BeginningOfMainBody(row_ptr->par))
1112 // if there is anything between the first char of the row and
1113 // the sepcified position that is not a newline and not a hfill,
1114 // the hfill will count, otherwise not
1115 LyXParagraph::size_type i = row_ptr->pos;
1116 while (i < pos && (row_ptr->par->IsNewline(i)
1117 || row_ptr->par->IsHfill(i)))
1124 void LyXText::SetHeightOfRow(Row * row_ptr) const
1126 /* get the maximum ascent and the maximum descent */
1127 int asc, maxasc, desc, maxdesc, pos_end, pos, labeladdon;
1128 float layoutasc = 0;
1129 float layoutdesc = 0;
1134 /* this must not happen before the currentrow for clear reasons.
1135 so the trick is just to set the current row onto this row */
1137 GetRow(row_ptr->par, row_ptr->pos, unused_y);
1139 /* ok , let us initialize the maxasc and maxdesc value.
1140 * This depends in LaTeX of the font of the last character
1141 * in the paragraph. The hack below is necessary because
1142 * of the possibility of open footnotes */
1144 /* Correction: only the fontsize count. The other properties
1145 are taken from the layoutfont. Nicer on the screen :) */
1147 LyXParagraph * par = row_ptr->par->LastPhysicalPar();
1148 LyXParagraph * firstpar = row_ptr->par->FirstPhysicalPar();
1150 LyXLayout const & layout = textclasslist.Style(parameters->textclass, firstpar->GetLayout());
1152 LyXFont font = GetFont(par, par->Last()-1);
1153 LyXFont::FONT_SIZE size = font.size();
1154 font = GetFont(par, -1);
1157 LyXFont labelfont = GetFont(par, -2);
1159 maxasc = int(font.maxAscent() *
1160 layout.spacing.getValue() *
1161 parameters->spacing.getValue());
1162 maxdesc = int(font.maxDescent() *
1163 layout.spacing.getValue() *
1164 parameters->spacing.getValue());
1166 pos_end = RowLast(row_ptr);
1170 // Check if any insets are larger
1171 for (pos = row_ptr->pos; pos <= pos_end; ++pos) {
1172 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_INSET) {
1173 tmpfont = GetFont(row_ptr->par, pos);
1174 tmpinset = row_ptr->par->GetInset(pos);
1176 asc = tmpinset->Ascent(tmpfont);
1177 desc = tmpinset->Descent(tmpfont);
1186 // Check if any custom fonts are larger (Asger)
1187 // This is not completely correct, but we can live with the small,
1188 // cosmetic error for now.
1189 LyXFont::FONT_SIZE maxsize = row_ptr->par->HighestFontInRange(row_ptr->pos,
1191 if (maxsize > font.size()) {
1192 font.setSize(maxsize);
1194 asc = font.maxAscent();
1195 desc = font.maxDescent();
1202 /* table stuff -- begin*/
1203 if (row_ptr->par->table){
1204 // stretch the rows a bit
1208 /* table stuff -- end*/
1210 // This is nicer with box insets:
1214 row_ptr->ascent_of_text = maxasc;
1216 /* is it a top line? */
1217 if (row_ptr->pos == 0
1218 && row_ptr->par == firstpar) {
1220 /* some parksips VERY EASY IMPLEMENTATION */
1221 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
1222 if (layout.isParagraph()
1223 && firstpar->GetDepth() == 0
1224 && firstpar->Previous())
1225 maxasc += parameters->getDefSkip().inPixels();
1226 else if (firstpar->Previous()
1227 && textclasslist.Style(parameters->textclass,
1228 firstpar->Previous()->GetLayout()).isParagraph()
1229 && firstpar->Previous()->GetDepth() == 0)
1230 // is it right to use defskip here too? (AS)
1231 maxasc += parameters->getDefSkip().inPixels();
1234 /* the paper margins */
1235 if (!row_ptr->par->previous)
1236 maxasc += LYX_PAPER_MARGIN;
1238 /* add the vertical spaces, that the user added */
1239 if (firstpar->added_space_top.kind() != VSpace::NONE)
1240 maxasc += int(firstpar->added_space_top.inPixels());
1242 /* do not forget the DTP-lines!
1243 * there height depends on the font of the nearest character */
1244 if (firstpar->line_top)
1245 maxasc += 2 * GetFont(firstpar, 0).ascent('x');
1247 /* and now the pagebreaks */
1248 if (firstpar->pagebreak_top)
1249 maxasc += 3 * DefaultHeight();
1251 /* this is special code for the chapter, since the label of this
1252 * layout is printed in an extra row */
1253 if (layout.labeltype == LABEL_COUNTER_CHAPTER
1254 && parameters->secnumdepth>= 0) {
1255 labeladdon = int(labelfont.maxDescent() *
1256 layout.spacing.getValue() *
1257 parameters->spacing.getValue())
1258 + int(labelfont.maxAscent() *
1259 layout.spacing.getValue() *
1260 parameters->spacing.getValue());
1263 /* special code for the top label */
1264 if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
1265 || layout.labeltype == LABEL_BIBLIO
1266 || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1267 && row_ptr->par->IsFirstInSequence()
1268 && !row_ptr->par->GetLabestring().empty()) {
1270 (labelfont.maxAscent() *
1271 layout.spacing.getValue() *
1272 parameters->spacing.getValue())
1273 +(labelfont.maxDescent() *
1274 layout.spacing.getValue() *
1275 parameters->spacing.getValue())
1276 + layout.topsep * DefaultHeight()
1277 + layout.labelbottomsep * DefaultHeight());
1280 /* and now the layout spaces, for example before and after a section,
1281 * or between the items of a itemize or enumerate environment */
1283 if (!firstpar->pagebreak_top) {
1284 LyXParagraph *prev = row_ptr->par->Previous();
1286 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth());
1287 if (prev && prev->GetLayout() == firstpar->GetLayout()
1288 && prev->GetDepth() == firstpar->GetDepth()
1289 && prev->GetLabelWidthString() == firstpar->GetLabelWidthString())
1291 layoutasc = (layout.itemsep * DefaultHeight());
1293 else if (row_ptr->previous) {
1294 tmptop = layout.topsep;
1296 if (row_ptr->previous->par->GetDepth() >= row_ptr->par->GetDepth())
1297 tmptop-= textclasslist.Style(parameters->textclass, row_ptr->previous->par->GetLayout()).bottomsep;
1300 layoutasc = (tmptop * DefaultHeight());
1302 else if (row_ptr->par->line_top){
1303 tmptop = layout.topsep;
1306 layoutasc = (tmptop * DefaultHeight());
1309 prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth()-1);
1311 maxasc += int(textclasslist.Style(parameters->textclass,
1312 prev->GetLayout()).parsep * DefaultHeight());
1315 if (firstpar->Previous()
1316 && firstpar->Previous()->GetDepth() == 0
1317 && firstpar->Previous()->GetLayout() != firstpar->GetLayout()) {
1320 else if (firstpar->Previous()){
1321 maxasc += int(layout.parsep * DefaultHeight());
1327 /* is it a bottom line? */
1328 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
1329 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
1331 /* the paper margins */
1333 maxdesc += LYX_PAPER_MARGIN;
1335 /* add the vertical spaces, that the user added */
1336 if (firstpar->added_space_bottom.kind() != VSpace::NONE)
1337 maxdesc += int(firstpar->added_space_bottom.inPixels());
1339 /* do not forget the DTP-lines!
1340 * there height depends on the font of the nearest character */
1341 if (firstpar->line_bottom)
1342 maxdesc += 2 * (GetFont(par, par->Last()-1).ascent('x'));
1344 /* and now the pagebreaks */
1345 if (firstpar->pagebreak_bottom)
1346 maxdesc += 3 * DefaultHeight();
1348 /* and now the layout spaces, for example before and after a section,
1349 * or between the items of a itemize or enumerate environment */
1350 if (!firstpar->pagebreak_bottom && row_ptr->par->Next()) {
1351 LyXParagraph *nextpar = row_ptr->par->Next();
1352 LyXParagraph *comparepar = row_ptr->par;
1356 if (comparepar->GetDepth() > nextpar->GetDepth()) {
1357 usual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1358 comparepar = comparepar->DepthHook(nextpar->GetDepth());
1359 if (comparepar->GetLayout()!= nextpar->GetLayout()
1360 || nextpar->GetLabelWidthString() !=
1361 comparepar->GetLabelWidthString())
1362 unusual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1364 if (unusual > usual)
1365 layoutdesc = unusual;
1369 else if (comparepar->GetDepth() == nextpar->GetDepth()) {
1371 if (comparepar->GetLayout()!= nextpar->GetLayout()
1372 || nextpar->GetLabelWidthString() !=
1373 comparepar->GetLabelWidthString())
1374 layoutdesc = int(textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight());
1379 /* incalculate the layout spaces */
1380 maxasc += int(layoutasc * 2 / (2 + firstpar->GetDepth()));
1381 maxdesc += int(layoutdesc * 2 / (2 + firstpar->GetDepth()));
1383 /* table stuff -- begin*/
1384 if (row_ptr->par->table){
1385 maxasc += row_ptr->par->table->
1386 AdditionalHeight(NumberOfCell(row_ptr->par, row_ptr->pos));
1388 /* table stuff -- end*/
1390 /* calculate the new height of the text */
1391 height -= row_ptr->height;
1393 row_ptr->height= maxasc+maxdesc+labeladdon;
1394 row_ptr->baseline= maxasc+labeladdon;
1396 height += row_ptr->height;
1400 /* Appends the implicit specified paragraph behind the specified row,
1401 * start at the implicit given position */
1402 void LyXText::AppendParagraph(Row * row) const
1404 bool not_ready = true;
1406 // The last character position of a paragraph is an invariant so we can
1407 // safely get it here. (Asger)
1408 int lastposition = row->par->Last();
1411 // Get the next breakpoint
1412 int z = NextBreakPoint(row, paperwidth);
1416 // Insert the new row
1417 if (z < lastposition) {
1419 InsertRow(row, row->par, z);
1426 // Set the dimensions of the row
1427 tmprow->fill = Fill(tmprow, paperwidth);
1428 SetHeightOfRow(tmprow);
1430 } while (not_ready);
1434 void LyXText::BreakAgain(Row * row) const
1436 bool not_ready = true;
1439 /* get the next breakpoint */
1440 LyXParagraph::size_type z =
1441 NextBreakPoint(row, paperwidth);
1444 if (z < row->par->Last() ) {
1445 if (!row->next || (row->next && row->next->par != row->par)) {
1448 InsertRow(row, row->par, z);
1455 not_ready = false; // the rest will not change
1461 /* if there are some rows too much, delete them */
1462 /* only if you broke the whole paragraph! */
1463 Row * tmprow2 = row;
1464 while (tmprow2->next && tmprow2->next->par == row->par) {
1465 tmprow2 = tmprow2->next;
1467 while (tmprow2 != row) {
1468 tmprow2 = tmprow2->previous;
1469 RemoveRow(tmprow2->next);
1474 /* set the dimensions of the row */
1475 tmprow->fill = Fill(tmprow, paperwidth);
1476 SetHeightOfRow(tmprow);
1477 } while (not_ready);
1481 /* this is just a little changed version of break again */
1482 void LyXText::BreakAgainOneRow(Row * row)
1484 /* get the next breakpoint */
1485 LyXParagraph::size_type z = NextBreakPoint(row, paperwidth);
1488 if (z < row->par->Last() ) {
1489 if (!row->next || (row->next && row->next->par != row->par)) {
1490 /* insert a new row */
1492 InsertRow(row, row->par, z);
1504 /* if there are some rows too much, delete them */
1505 /* only if you broke the whole paragraph! */
1506 Row * tmprow2 = row;
1507 while (tmprow2->next && tmprow2->next->par == row->par) {
1508 tmprow2 = tmprow2->next;
1510 while (tmprow2 != row) {
1511 tmprow2 = tmprow2->previous;
1512 RemoveRow(tmprow2->next);
1516 /* set the dimensions of the row */
1517 tmprow->fill = Fill(tmprow, paperwidth);
1518 SetHeightOfRow(tmprow);
1522 void LyXText::BreakParagraph(char keep_layout)
1524 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
1525 cursor.par->GetLayout());
1527 /* table stuff -- begin */
1528 if (cursor.par->table) {
1529 // breaking of tables is only allowed at the beginning or the end */
1530 if (cursor.pos && cursor.pos < cursor.par->size() &&
1531 !cursor.par->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par, cursor.pos)))
1532 return; // no breaking of tables allowed
1534 /* table stuff -- end */
1536 // this is only allowed, if the current paragraph is not empty or caption
1537 if ((cursor.par->Last() <= 0 && !cursor.par->IsDummy())
1539 layout.labeltype!= LABEL_SENSITIVE)
1542 SetUndo(Undo::INSERT,
1543 cursor.par->ParFromPos(cursor.pos)->previous,
1544 cursor.par->ParFromPos(cursor.pos)->next);
1546 /* table stuff -- begin */
1547 if (cursor.par->table) {
1548 int cell = NumberOfCell(cursor.par, cursor.pos);
1549 if (cursor.par->table->ShouldBeVeryLastCell(cell))
1550 SetCursor(cursor.par, cursor.par->text.size());
1552 /* table stuff -- end */
1554 // please break always behind a space
1555 if (cursor.pos < cursor.par->Last()
1556 && cursor.par->IsLineSeparator(cursor.pos))
1559 // break the paragraph
1563 keep_layout = layout.isEnvironment();
1564 cursor.par->BreakParagraph(cursor.pos, keep_layout);
1566 /* table stuff -- begin */
1567 if (cursor.par->table){
1568 // the table should stay with the contents
1570 cursor.par->Next()->table = cursor.par->table;
1571 cursor.par->table = 0;
1574 /* table stuff -- end */
1576 // well this is the caption hack since one caption is really enough
1577 if (layout.labeltype == LABEL_SENSITIVE){
1579 cursor.par->SetLayout(0); // set to standard-layout
1581 cursor.par->Next()->SetLayout(0); // set to standard-layout
1584 /* if the cursor is at the beginning of a row without prior newline,
1586 * This touches only the screen-update. Otherwise we would may have
1587 * an empty row on the screen */
1588 if (cursor.pos && !cursor.row->par->IsNewline(cursor.row->pos -1) &&
1589 cursor.row->pos == cursor.pos) {
1593 status = LyXText::NEED_MORE_REFRESH;
1594 refresh_row = cursor.row;
1595 refresh_y = cursor.y - cursor.row->baseline;
1597 // Do not forget the special right address boxes
1598 if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1599 while (refresh_row->previous &&
1600 refresh_row->previous->par == refresh_row->par) {
1601 refresh_row = refresh_row->previous;
1602 refresh_y -= refresh_row->height;
1605 RemoveParagraph(cursor.row);
1607 // set the dimensions of the cursor row
1608 cursor.row->fill = Fill(cursor.row, paperwidth);
1610 SetHeightOfRow(cursor.row);
1612 while (!cursor.par->Next()->table && cursor.par->Next()->Last()
1613 && cursor.par->Next()->IsNewline(0))
1614 cursor.par->Next()->Erase(0);
1616 InsertParagraph(cursor.par->Next(), cursor.row);
1618 UpdateCounters(cursor.row->previous);
1620 /* This check is necessary. Otherwise the new empty paragraph will
1621 * be deleted automatically. And it is more friendly for the user! */
1623 SetCursor(cursor.par->Next(), 0);
1625 SetCursor(cursor.par, 0);
1627 if (cursor.row->next)
1628 BreakAgain(cursor.row->next);
1634 void LyXText::OpenFootnote()
1636 LyXParagraph * endpar,* tmppar;
1639 LyXParagraph * par = cursor.par->ParFromPos(cursor.pos);
1641 /* if there is no footnote in this paragraph, just return. */
1643 || par->next->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1646 /* ok, move the cursor right before the footnote */
1648 /* just a little faster than using CursorRight() */
1649 for (cursor.pos = 0;
1650 cursor.par->ParFromPos(cursor.pos) != par; cursor.pos++);
1651 /* now the cursor is at the beginning of the physical par */
1652 SetCursor(cursor.par,
1653 cursor.pos + cursor.par->ParFromPos(cursor.pos)->text.size());
1655 /* the cursor must be exactly before the footnote */
1656 par = cursor.par->ParFromPos(cursor.pos);
1658 status = LyXText::NEED_MORE_REFRESH;
1659 refresh_row = cursor.row;
1660 refresh_y = cursor.y - cursor.row->baseline;
1662 tmppar = cursor.par;
1663 endpar = cursor.par->Next();
1666 tmppar->OpenFootnote(cursor.pos);
1667 RemoveParagraph(row);
1668 /* set the dimensions of the cursor row */
1669 row->fill = Fill(row, paperwidth);
1670 SetHeightOfRow(row);
1671 tmppar = tmppar->Next();
1673 while (tmppar != endpar) {
1675 InsertParagraph(tmppar, row);
1676 while (row->next && row->next->par == tmppar)
1678 tmppar = tmppar->Next();
1681 SetCursor(par->next, 0);
1682 sel_cursor = cursor;
1686 /* table stuff -- begin*/
1688 void LyXText::TableFeatures(int feature, string const & val) const
1690 if (!cursor.par->table)
1691 return; /* this should never happen */
1693 int actCell = NumberOfCell(cursor.par, cursor.pos);
1694 SetUndo(Undo::FINISH,
1695 cursor.par->ParFromPos(cursor.pos)->previous,
1696 cursor.par->ParFromPos(cursor.pos)->next);
1699 case LyXTable::SET_PWIDTH:
1700 cursor.par->table->SetPWidth(actCell, val);
1702 case LyXTable::SET_SPECIAL_COLUMN:
1703 case LyXTable::SET_SPECIAL_MULTI:
1704 cursor.par->table->SetAlignSpecial(actCell, val, feature);
1713 void LyXText::TableFeatures(int feature) const
1716 int setAlign = LYX_ALIGN_LEFT;
1720 if (!cursor.par->table)
1721 return; /* this should never happen */
1723 int actCell = NumberOfCell(cursor.par, cursor.pos);
1724 SetUndo(Undo::FINISH,
1725 cursor.par->ParFromPos(cursor.pos)->previous,
1726 cursor.par->ParFromPos(cursor.pos)->next);
1729 case LyXTable::ALIGN_LEFT:
1730 setAlign= LYX_ALIGN_LEFT;
1732 case LyXTable::ALIGN_RIGHT:
1733 setAlign= LYX_ALIGN_RIGHT;
1735 case LyXTable::ALIGN_CENTER:
1736 setAlign= LYX_ALIGN_CENTER;
1742 case LyXTable::APPEND_ROW: {
1743 LyXParagraph::size_type pos = cursor.pos;
1745 /* move to the next row */
1746 int cell_org = actCell;
1747 int cell = cell_org;
1749 // if there is a ContRow following this row I have to add
1750 // the row after the ContRow's
1751 if ((pos < cursor.par->Last()) &&
1752 cursor.par->table->RowHasContRow(cell_org)) {
1753 while((pos < cursor.par->Last()) &&
1754 !cursor.par->table->IsContRow(cell)) {
1755 while (pos < cursor.par->Last() &&
1756 !cursor.par->IsNewline(pos))
1758 if (pos < cursor.par->Last())
1762 while((pos < cursor.par->Last()) &&
1763 cursor.par->table->IsContRow(cell)) {
1764 while (pos < cursor.par->Last() &&
1765 !cursor.par->IsNewline(pos))
1767 if (pos < cursor.par->Last())
1772 if (pos < cursor.par->Last())
1775 while (pos < cursor.par->Last() &&
1776 (cell == cell_org || !cursor.par->table->IsFirstCell(cell))){
1777 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1779 if (pos < cursor.par->Last())
1784 /* insert the new cells */
1785 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1786 for (int i = 0; i < number; ++i)
1787 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1789 /* append the row into the table */
1790 cursor.par->table->AppendRow(cell_org);
1794 case LyXTable::APPEND_CONT_ROW: {
1795 LyXParagraph::size_type pos = cursor.pos;
1796 /* move to the next row */
1797 int cell_org = actCell;
1798 int cell = cell_org;
1800 // if there is already a controw but not for this cell
1801 // the AppendContRow sets only the right values but does
1802 // not actually add a row
1803 if (cursor.par->table->RowHasContRow(cell_org) &&
1804 (cursor.par->table->CellHasContRow(cell_org)<0)) {
1805 cursor.par->table->AppendContRow(cell_org);
1809 while (pos < cursor.par->Last() &&
1811 || !cursor.par->table->IsFirstCell(cell))){
1812 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1814 if (pos < cursor.par->Last())
1819 /* insert the new cells */
1820 int number = cursor.par->table->NumberOfCellsInRow(cell_org);
1821 for (int i = 0; i < number; ++i)
1822 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1824 /* append the row into the table */
1825 cursor.par->table->AppendContRow(cell_org);
1829 case LyXTable::APPEND_COLUMN: {
1830 LyXParagraph::size_type pos = 0;
1831 int cell_org = actCell;
1834 if (pos && (cursor.par->IsNewline(pos-1))){
1835 if (cursor.par->table->AppendCellAfterCell(cell_org, cell)){
1836 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
1837 if (pos <= cursor.pos)
1844 } while (pos <= cursor.par->Last());
1845 /* remember that the very last cell doesn't end with a newline.
1846 This saves one byte memory per table ;-) */
1847 if (cursor.par->table->AppendCellAfterCell(cell_org, cell))
1848 cursor.par->InsertChar(cursor.par->Last(), LyXParagraph::META_NEWLINE);
1850 /* append the column into the table */
1851 cursor.par->table->AppendColumn(cell_org);
1856 case LyXTable::DELETE_ROW:
1857 if (current_view->the_locking_inset)
1858 current_view->unlockInset(current_view->the_locking_inset);
1859 RemoveTableRow(&cursor);
1863 case LyXTable::DELETE_COLUMN: {
1864 LyXParagraph::size_type pos = 0;
1865 int cell_org = actCell;
1867 if (current_view->the_locking_inset)
1868 current_view->unlockInset(current_view->the_locking_inset);
1870 if (!pos || (cursor.par->IsNewline(pos-1))){
1871 if (cursor.par->table->DeleteCellIfColumnIsDeleted(cell, cell_org)){
1873 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
1874 cursor.par->Erase(pos);
1875 if (pos < cursor.par->Last())
1876 cursor.par->Erase(pos);
1878 cursor.par->Erase(pos - 1); // the missing newline at the end of a table
1879 --pos; // because of pos++ below
1884 } while (pos <= cursor.par->Last());
1886 /* delete the column from the table */
1887 cursor.par->table->DeleteColumn(cell_org);
1889 /* set the cursor to the beginning of the table, where else? */
1894 case LyXTable::TOGGLE_LINE_TOP:
1895 lineSet = !cursor.par->table->TopLine(actCell);
1897 cursor.par->table->SetTopLine(actCell, lineSet);
1899 LyXParagraph::size_type i;
1901 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
1902 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
1903 cursor.par->table->SetTopLine(n, lineSet);
1911 case LyXTable::TOGGLE_LINE_BOTTOM:
1912 lineSet = !cursor.par->table->BottomLine(actCell);
1914 cursor.par->table->SetBottomLine(actCell, lineSet);
1916 LyXParagraph::size_type i;
1918 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
1919 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
1920 cursor.par->table->SetBottomLine(n, lineSet);
1928 case LyXTable::TOGGLE_LINE_LEFT:
1929 lineSet = !cursor.par->table->LeftLine(actCell);
1931 cursor.par->table->SetLeftLine(actCell, lineSet);
1933 LyXParagraph::size_type i;
1935 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
1936 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1937 cursor.par->table->SetLeftLine(n, lineSet);
1945 case LyXTable::TOGGLE_LINE_RIGHT:
1946 lineSet = !cursor.par->table->RightLine(actCell);
1948 cursor.par->table->SetRightLine(actCell, lineSet);
1951 LyXParagraph::size_type i = sel_start_cursor.pos;
1952 for (; i <= sel_end_cursor.pos; ++i) {
1953 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1954 cursor.par->table->SetRightLine(n, lineSet);
1962 case LyXTable::ALIGN_LEFT:
1963 case LyXTable::ALIGN_RIGHT:
1964 case LyXTable::ALIGN_CENTER:
1966 cursor.par->table->SetAlignment(actCell, setAlign);
1969 LyXParagraph::size_type i = sel_start_cursor.pos;
1970 for (; i <= sel_end_cursor.pos; ++i) {
1971 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
1972 cursor.par->table->SetAlignment(n, setAlign);
1980 case LyXTable::DELETE_TABLE:
1981 SetCursorIntern(cursor.par, 0);
1982 delete cursor.par->table;
1983 cursor.par->table = 0;
1984 // temporary: Should put table in simple_cut_buffer (with before and after
1985 // dummy-paragraph !!
1986 // not necessar anymore with UNDO :)
1987 for (LyXParagraph::size_type i =
1988 cursor.par->text.size() - 1; i >= 0; --i)
1989 cursor.par->Erase(i);
1993 case LyXTable::MULTICOLUMN: {
1995 // check wether we are completly in a multicol
1996 int multicol = cursor.par->table->IsMultiColumn(actCell);
1997 if (multicol && selection && sel_start_cursor.row == sel_end_cursor.row){
1998 multicol = NumberOfCell(sel_start_cursor.par, sel_start_cursor.pos)
1999 == NumberOfCell(sel_end_cursor.par, sel_end_cursor.pos);
2003 int newlines = cursor.par->table->UnsetMultiColumn(actCell);
2004 LyXParagraph::size_type pos = cursor.pos;
2005 while (pos < cursor.par->Last() && !cursor.par->IsNewline(pos))
2007 for (; newlines; --newlines)
2008 cursor.par->InsertChar(pos, LyXParagraph::META_NEWLINE);
2013 // selection must be in one row (or no selection)
2015 cursor.par->table->SetMultiColumn(NumberOfCell(cursor.par,
2022 if (sel_start_cursor.row == sel_end_cursor.row){
2023 LyXParagraph::size_type i;
2025 for (i = sel_start_cursor.pos;
2026 i < sel_end_cursor.pos; ++i){
2027 if (sel_start_cursor.par->IsNewline(i)){
2028 sel_start_cursor.par->Erase(i);
2029 // check for double-blanks
2030 if ((i && !sel_start_cursor.par->IsLineSeparator(i-1))
2032 (i < sel_start_cursor.par->Last()
2033 && !sel_start_cursor.par->IsLineSeparator(i)))
2034 sel_start_cursor.par->InsertChar(i, ' ');
2036 sel_end_cursor.pos--;
2043 SetMultiColumn(NumberOfCell(sel_start_cursor.par,
2044 sel_start_cursor.pos),
2046 cursor.pos = sel_start_cursor.pos;
2051 WriteAlert(_("Impossible Operation!"),
2052 _("Multicolumns can only be horizontally."),
2059 case LyXTable::SET_ALL_LINES:
2061 case LyXTable::UNSET_ALL_LINES:
2063 cursor.par->table->SetAllLines(NumberOfCell(cursor.par,
2067 LyXParagraph::size_type i;
2069 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2070 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2071 cursor.par->table->SetAllLines(n, setLines);
2078 case LyXTable::SET_LONGTABLE:
2079 cursor.par->table->SetLongTable(true);
2081 case LyXTable::UNSET_LONGTABLE:
2082 cursor.par->table->SetLongTable(false);
2084 case LyXTable::SET_ROTATE_TABLE:
2085 cursor.par->table->SetRotateTable(true);
2087 case LyXTable::UNSET_ROTATE_TABLE:
2088 cursor.par->table->SetRotateTable(false);
2090 case LyXTable::SET_ROTATE_CELL:
2092 cursor.par->table->SetRotateCell(actCell, true);
2094 LyXParagraph::size_type i;
2096 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i){
2097 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2098 cursor.par->table->SetRotateCell(n, true);
2104 case LyXTable::UNSET_ROTATE_CELL:
2106 cursor.par->table->SetRotateCell(actCell, false);
2109 LyXParagraph::size_type i = sel_start_cursor.pos;
2110 for (; i <= sel_end_cursor.pos; ++i) {
2111 if ((n= NumberOfCell(sel_start_cursor.par, i)) != m) {
2112 cursor.par->table->SetRotateCell(n, false);
2118 case LyXTable::SET_LINEBREAKS:
2119 what = !cursor.par->table->Linebreaks(cursor.par->table->FirstVirtualCell(actCell));
2121 cursor.par->table->SetLinebreaks(actCell, what);
2123 LyXParagraph::size_type i;
2125 for (i = sel_start_cursor.pos; i <= sel_end_cursor.pos; ++i) {
2126 if ((n = NumberOfCell(sel_start_cursor.par, i)) != m) {
2127 cursor.par->table->SetLinebreaks(n, what);
2133 case LyXTable::SET_LTFIRSTHEAD:
2134 cursor.par->table->SetLTHead(actCell, true);
2136 case LyXTable::SET_LTHEAD:
2137 cursor.par->table->SetLTHead(actCell, false);
2139 case LyXTable::SET_LTFOOT:
2140 cursor.par->table->SetLTFoot(actCell, false);
2142 case LyXTable::SET_LTLASTFOOT:
2143 cursor.par->table->SetLTFoot(actCell, true);
2145 case LyXTable::SET_LTNEWPAGE:
2146 what = !cursor.par->table->LTNewPage(actCell);
2147 cursor.par->table->SetLTNewPage(actCell, what);
2153 void LyXText::InsertCharInTable(char c)
2158 bool jumped_over_space;
2160 /* first check, if there will be two blanks together or a blank at
2161 * the beginning of a paragraph.
2162 * I decided to handle blanks like normal characters, the main
2163 * difference are the special checks when calculating the row.fill
2164 * (blank does not count at the end of a row) and the check here */
2166 LyXFont realtmpfont = real_current_font;
2167 LyXFont rawtmpfont = current_font; /* store the current font.
2168 * This is because of the use
2169 * of cursor movements. The moving
2170 * cursor would refresh the
2173 // Get the font that is used to calculate the baselineskip
2174 LyXParagraph::size_type const lastpos =
2176 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2178 jumped_over_space = false;
2179 if (IsLineSeparatorChar(c)) {
2181 /* avoid double blanks but insert the new blank because
2182 * of a possible font change */
2183 if (cursor.pos < lastpos &&
2184 cursor.par->IsLineSeparator(cursor.pos))
2186 cursor.par->Erase(cursor.pos);
2187 jumped_over_space = true;
2189 else if ((cursor.pos > 0 &&
2190 cursor.par->IsLineSeparator(cursor.pos - 1))
2191 || (cursor.pos > 0 && cursor.par->IsNewline(cursor.pos - 1))
2192 || (cursor.pos == 0 &&
2193 !(cursor.par->Previous()
2194 && cursor.par->Previous()->footnoteflag
2195 == LyXParagraph::OPEN_FOOTNOTE)))
2198 else if (IsNewlineChar(c)) {
2199 if (!IsEmptyTableCell()) {
2200 TableFeatures(LyXTable::APPEND_CONT_ROW);
2207 y = cursor.y - row->baseline;
2208 if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset
2209 * already inserted the character */
2210 cursor.par->InsertChar(cursor.pos, c);
2211 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2213 if (!jumped_over_space) {
2214 /* refresh the positions */
2216 while (tmprow->next && tmprow->next->par == row->par) {
2217 tmprow = tmprow->next;
2224 CheckParagraphInTable(cursor.par, cursor.pos);
2226 current_font = rawtmpfont;
2227 real_current_font = realtmpfont;
2229 /* check, whether the last character's font has changed. */
2230 if (cursor.pos && cursor.pos == cursor.par->Last()
2231 && rawparfont != rawtmpfont)
2232 RedoHeightOfParagraph(cursor);
2236 void LyXText::CheckParagraphInTable(LyXParagraph * par,
2237 LyXParagraph::size_type pos)
2240 if (par->GetChar(pos) == LyXParagraph::META_INSET &&
2241 par->GetInset(pos) && par->GetInset(pos)->display()){
2242 par->GetInset(pos)->display(false);
2246 Row * row = GetRow(par, pos, y);
2248 int tmpheight = row->height;
2249 SetHeightOfRow(row);
2251 LyXParagraph::size_type tmp_pos = pos;
2252 /* update the table information */
2253 while (tmp_pos && !par->IsNewline(tmp_pos - 1))
2255 if (par->table->SetWidthOfCell(NumberOfCell(par, pos),
2256 WidthOfCell(par, tmp_pos))) {
2257 LyXCursor tmpcursor = cursor;
2258 SetCursorIntern(par, pos);
2259 /* make a complete redraw */
2260 RedoDrawingOfParagraph(cursor);
2264 /* redraw only the row */
2265 LyXCursor tmpcursor = cursor;
2266 SetCursorIntern(par, pos);
2268 refresh_x = cursor.x;
2270 refresh_pos = cursor.pos;
2273 if (tmpheight == row->height)
2274 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2276 status = LyXText::NEED_MORE_REFRESH;
2278 SetCursorIntern(cursor.par, cursor.pos);
2282 void LyXText::BackspaceInTable()
2284 Row * tmprow, * row;
2287 LyXFont rawtmpfont = current_font;
2288 LyXFont realtmpfont = real_current_font;
2290 // Get the font that is used to calculate the baselineskip
2291 int const lastpos = cursor.par->Last();
2292 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2294 if (cursor.pos == 0) {
2295 /* no pasting of table paragraphs */
2300 /* this is the code for a normal backspace, not pasting
2302 SetUndo(Undo::DELETE,
2303 cursor.par->ParFromPos(cursor.pos)->previous,
2304 cursor.par->ParFromPos(cursor.pos)->next);
2308 /* some insets are undeletable here */
2309 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
2310 if (!cursor.par->GetInset(cursor.pos)->Deletable())
2315 y = cursor.y - row->baseline;
2317 /* some special code when deleting a newline. */
2318 if (cursor.par->IsNewline(cursor.pos)) {
2323 cursor.par->Erase(cursor.pos);
2325 /* refresh the positions */
2327 while (tmprow->next && tmprow->next->par == row->par) {
2328 tmprow = tmprow->next;
2332 /* delete superfluous blanks */
2333 if (cursor.pos < cursor.par->Last() - 1 &&
2334 (cursor.par->IsLineSeparator(cursor.pos))) {
2336 if (cursor.pos == BeginningOfMainBody(cursor.par)
2338 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
2339 cursor.par->Erase(cursor.pos);
2340 /* refresh the positions */
2342 while (tmprow->next &&
2343 tmprow->next->par == row->par) {
2344 tmprow = tmprow->next;
2347 if (cursor.pos) /* move one character left */
2353 CheckParagraphInTable(cursor.par, cursor.pos);
2355 /* check, wether the last characters font has changed. */
2356 if (cursor.pos && cursor.pos == cursor.par->Last()
2357 && rawparfont != rawtmpfont)
2358 RedoHeightOfParagraph(cursor);
2360 /* restore the current font
2361 * That is what a user expects! */
2362 current_font = rawtmpfont;
2363 real_current_font = realtmpfont;
2365 SetCursorIntern(cursor.par, cursor.pos);
2368 /* table stuff -- end*/
2371 /* just a macro to make some thing easier. */
2372 void LyXText::RedoParagraph() const
2375 // I suspect this version will work
2378 RedoParagraphs(cursor, cursor.par->Next());
2379 SetCursorIntern(cursor.par, cursor.pos);
2381 LyXCursor tmpcursor = cursor;
2383 RedoParagraphs(cursor, cursor.par->Next());
2384 SetCursorIntern(tmpcursor.par, tmpcursor.pos);
2389 /* insert a character, moves all the following breaks in the
2390 * same Paragraph one to the right and make a rebreak */
2391 void LyXText::InsertChar(char c)
2393 SetUndo(Undo::INSERT,
2394 cursor.par->ParFromPos(cursor.pos)->previous,
2395 cursor.par->ParFromPos(cursor.pos)->next);
2397 /* When the free-spacing option is set for the current layout,
2398 * all spaces are converted to protected spaces. */
2399 bool freeSpacingBo =
2400 textclasslist.Style(parameters->textclass,
2401 cursor.row->par->GetLayout()).free_spacing;
2403 if (freeSpacingBo && IsLineSeparatorChar(c)
2404 && (!cursor.pos || cursor.par->IsLineSeparator(cursor.pos - 1)))
2405 c = LyXParagraph::META_PROTECTED_SEPARATOR;
2407 /* table stuff -- begin*/
2408 if (cursor.par->table) {
2409 InsertCharInTable(c);
2413 /* table stuff -- end*/
2415 /* First check, if there will be two blanks together or a blank at
2416 the beginning of a paragraph.
2417 I decided to handle blanks like normal characters, the main
2418 difference are the special checks when calculating the row.fill
2419 (blank does not count at the end of a row) and the check here */
2421 // The bug is triggered when we type in a description environment:
2422 // The current_font is not changed when we go from label to main text
2423 // and it should (along with realtmpfont) when we type the space.
2424 #ifdef WITH_WARNINGS
2425 #warning There is a bug here! (Asger)
2428 LyXFont realtmpfont = real_current_font;
2429 LyXFont rawtmpfont = current_font; /* store the current font.
2430 * This is because of the use
2431 * of cursor movements. The moving
2432 * cursor would refresh the
2435 // Get the font that is used to calculate the baselineskip
2436 LyXParagraph::size_type lastpos = cursor.par->Last();
2437 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
2439 bool jumped_over_space = false;
2441 if (IsLineSeparatorChar(c)) {
2442 #ifndef FIX_DOUBLE_SPACE
2443 if (cursor.pos < lastpos
2444 && cursor.par->IsLineSeparator(cursor.pos)) {
2445 /* the user inserted a space before a space. So we
2446 * will just make a CursorRight. BUT: The font of this
2447 * space should be set to current font. That is why
2448 * we need to rebreak perhaps. If there is a protected
2449 * blank at the end of a row we have to force
2452 current_view->owner()->getMiniBuffer()
2453 ->Set(_("You cannot type two spaces this way. "
2454 " Please read the Tutorial."));
2456 // How can this ever happen?
2457 if (cursor.pos == RowLast(cursor.row)
2458 && !IsLineSeparatorChar(c))
2459 cursor.row->fill = -1; // force rebreak
2460 cursor.par->Erase(cursor.pos);
2461 jumped_over_space = true;
2463 // Seems to me that this works just as well.
2471 && cursor.par->IsLineSeparator(cursor.pos - 1))
2473 && cursor.par->IsNewline(cursor.pos - 1))
2475 && !(cursor.par->Previous()
2476 && cursor.par->Previous()->footnoteflag
2477 == LyXParagraph::OPEN_FOOTNOTE))) {
2478 if (cursor.pos == 0 )
2479 current_view->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
2481 current_view->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial."));
2485 } else if (IsNewlineChar(c)) {
2486 if (cursor.par->FirstPhysicalPar() == cursor.par
2487 && cursor.pos <= BeginningOfMainBody(cursor.par)) {
2491 /* No newline at first position
2492 * of a paragraph or behind labels.
2493 * TeX does not allow that. */
2495 if (cursor.pos < cursor.par->Last() &&
2496 cursor.par->IsLineSeparator(cursor.pos))
2497 CursorRightIntern(); // newline always after a blank!
2498 cursor.row->fill = -1; // to force a new break
2501 // the display inset stuff
2502 if (cursor.row->par->GetChar(cursor.row->pos) == LyXParagraph::META_INSET
2503 && cursor.row->par->GetInset(cursor.row->pos)
2504 && cursor.row->par->GetInset(cursor.row->pos)->display())
2505 cursor.row->fill = -1; // to force a new break
2507 // get the cursor row fist
2508 Row * row = cursor.row;
2509 long y = cursor.y - row->baseline;
2510 if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset
2511 * already insertet the character */
2512 cursor.par->InsertChar(cursor.pos, c);
2513 SetCharFont(cursor.par, cursor.pos, rawtmpfont);
2515 if (!jumped_over_space) {
2516 // refresh the positions
2518 while (tmprow->next && tmprow->next->par == row->par) {
2519 tmprow = tmprow->next;
2524 // Is there a break one row above
2525 if ((cursor.par->IsLineSeparator(cursor.pos)
2526 || cursor.par->IsNewline(cursor.pos)
2527 || cursor.row->fill == -1)
2528 && row->previous && row->previous->par == row->par) {
2529 LyXParagraph::size_type z = NextBreakPoint(row->previous,
2531 if ( z >= row->pos) {
2534 // set the dimensions of the row above
2535 row->previous->fill = Fill(row->previous, paperwidth);
2537 SetHeightOfRow(row->previous);
2539 y -= row->previous->height;
2541 refresh_row = row->previous;
2542 status = LyXText::NEED_MORE_REFRESH;
2544 BreakAgainOneRow(row);
2546 current_font = rawtmpfont;
2547 real_current_font = realtmpfont;
2548 SetCursor(cursor.par, cursor.pos + 1, false);
2549 /* cursor MUST be in row now */
2551 if (row->next && row->next->par == row->par)
2552 need_break_row = row->next;
2556 // check, wether the last characters font has changed.
2557 if (cursor.pos && cursor.pos == cursor.par->Last()
2558 && rawparfont != rawtmpfont)
2559 RedoHeightOfParagraph(cursor);
2566 /* recalculate the fill of the row */
2567 if (row->fill >= 0) /* needed because a newline
2568 * will set fill to -1. Otherwise
2569 * we would not get a rebreak! */
2570 row->fill = Fill(row, paperwidth);
2571 if (row->fill < 0 ) {
2574 refresh_x = cursor.x;
2575 refresh_pos = cursor.pos;
2576 status = LyXText::NEED_MORE_REFRESH;
2577 BreakAgainOneRow(row);
2578 /* will the cursor be in another row now? */
2579 if (RowLast(row) <= cursor.pos + 1 && row->next) {
2580 if (row->next && row->next->par == row->par)
2584 BreakAgainOneRow(row);
2586 current_font = rawtmpfont;
2587 real_current_font = realtmpfont;
2588 SetCursor(cursor.par, cursor.pos + 1, false);
2589 if (row->next && row->next->par == row->par)
2590 need_break_row = row->next;
2595 refresh_x = cursor.x;
2597 refresh_pos = cursor.pos;
2599 int tmpheight = row->height;
2600 SetHeightOfRow(row);
2601 if (tmpheight == row->height)
2602 status = LyXText::NEED_VERY_LITTLE_REFRESH;
2604 status = LyXText::NEED_MORE_REFRESH;
2606 current_font = rawtmpfont;
2607 real_current_font = realtmpfont;
2608 SetCursor(cursor.par, cursor.pos + 1, false);
2611 /* check, wether the last characters font has changed. */
2612 if (cursor.pos && cursor.pos == cursor.par->Last()
2613 && rawparfont != rawtmpfont) {
2614 RedoHeightOfParagraph(cursor);
2616 /* now the special right address boxes */
2617 if (textclasslist.Style(parameters->textclass,
2618 cursor.par->GetLayout()).margintype
2619 == MARGIN_RIGHT_ADDRESS_BOX) {
2620 RedoDrawingOfParagraph(cursor);
2628 void LyXText::charInserted()
2630 // Here we could call FinishUndo for every 20 characters inserted.
2631 // This is from my experience how emacs does it.
2632 static unsigned int counter = 0;
2641 void LyXText::PrepareToPrint(Row * row, float & x,
2642 float & fill_separator,
2644 float & fill_label_hfill,
2649 float w = row->fill;
2651 fill_label_hfill = 0;
2653 fill_label_hfill = 0;
2655 LyXDirection direction = GetParDirection(row->par);
2657 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
2658 x = RightMargin(row);
2659 if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
2660 LyXFont font(LyXFont::ALL_SANE);
2661 font.setSize(LyXFont::SIZE_SMALL);
2662 x += font.textWidth("Mwide-figM", 10);
2666 x = LeftMargin(row);
2668 /* is there a manual margin with a manual label */
2669 if (textclasslist.Style(parameters->textclass,
2670 row->par->GetLayout()).margintype == MARGIN_MANUAL
2671 && textclasslist.Style(parameters->textclass,
2672 row->par->GetLayout()).labeltype == LABEL_MANUAL) {
2674 nlh = NumberOfLabelHfills(row) + 1; /* one more since labels
2675 * are left aligned*/
2676 if (nlh && !row->par->GetLabelWidthString().empty()) {
2677 fill_label_hfill = LabelFill(row) / nlh;
2681 /* are there any hfills in the row? */
2682 nh = NumberOfHfills(row);
2684 /* table stuff -- begin*/
2685 if (row->par->table) {
2686 w = paperwidth - row->par->table->WidthOfTable()
2687 - x - RightMargin(row);
2688 nh = 0; /* ignore hfills in tables */
2690 /* table stuff -- end*/
2695 /* is it block, flushleft or flushright?
2696 * set x how you need it */
2698 if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
2699 align = textclasslist.Style(parameters->textclass, row->par->GetLayout()).align;
2701 align = row->par->FirstPhysicalPar()->align;
2703 /* center displayed insets */
2704 if (row->par->GetChar(row->pos) == LyXParagraph::META_INSET
2705 && row->par->GetInset(row->pos)
2706 && row->par->GetInset(row->pos)->display())
2707 align = LYX_ALIGN_CENTER;
2710 case LYX_ALIGN_BLOCK:
2711 ns = NumberOfSeparators(row);
2712 if (ns && row->next && row->next->par == row->par &&
2713 !(row->next->par->IsNewline(row->next->pos-1))
2714 && !(row->next->par->GetChar(row->next->pos) == LyXParagraph::META_INSET
2715 && row->next->par->GetInset(row->next->pos)
2716 && row->next->par->GetInset(row->next->pos)->display())
2718 fill_separator = w / ns;
2719 else if (direction == LYX_DIR_RIGHT_TO_LEFT)
2722 case LYX_ALIGN_RIGHT:
2725 case LYX_ALIGN_CENTER:
2733 ComputeBidiTables(row);
2734 if (direction == LYX_DIR_RIGHT_TO_LEFT) {
2735 LyXParagraph::size_type main_body =
2736 BeginningOfMainBody(row->par);
2737 LyXParagraph::size_type last = RowLast(row);
2739 if (row->pos <= last
2741 && last != vis2log(last)
2742 && row->par->IsLineSeparator(last)) {
2743 if (!(main_body > 0 && main_body-1 == last))
2744 x -= fill_separator+SingleWidth(row->par,last);
2745 } else if (main_body > 0 &&
2746 (main_body-1 > last ||
2747 !row->par->IsLineSeparator(main_body-1))) {
2748 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
2749 row->par->GetLayout());
2750 x += GetFont(row->par, -2).stringWidth(layout.labelsep);
2751 if (main_body-1 <= last)
2752 x += fill_label_hfill;
2757 /* important for the screen */
2760 /* the cursor set functions have a special mechanism. When they
2761 * realize, that you left an empty paragraph, they will delete it.
2762 * They also delete the corresponding row */
2764 void LyXText::CursorRightOneWord() const
2766 // treat floats, HFills and Insets as words
2767 LyXCursor tmpcursor = cursor;
2769 if (tmpcursor.pos == tmpcursor.par->Last()
2770 && tmpcursor.par->Next())
2772 tmpcursor.par = tmpcursor.par->Next();
2777 // Skip through initial nonword stuff.
2778 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2779 ! tmpcursor.par->IsWord( tmpcursor.pos ) )
2781 // printf("Current pos1 %d", tmpcursor.pos) ;
2785 // Advance through word.
2786 while ( tmpcursor.pos < tmpcursor.par->Last() &&
2787 tmpcursor.par->IsWord( tmpcursor.pos ) )
2789 // printf("Current pos2 %d", tmpcursor.pos) ;
2794 SetCursor(tmpcursor.par, tmpcursor.pos);
2798 void LyXText::CursorTab() const
2800 if (cursor.par->table) {
2801 int cell = NumberOfCell(cursor.par, cursor.pos);
2802 while(cursor.par->table->IsContRow(cell)) {
2804 cell = NumberOfCell(cursor.par, cursor.pos);
2806 if (cursor.par->table->ShouldBeVeryLastCell(cell))
2807 TableFeatures(LyXTable::APPEND_ROW);
2809 LyXCursor tmpcursor = cursor;
2810 while (tmpcursor.pos < tmpcursor.par->Last()
2811 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2814 if (tmpcursor.pos == tmpcursor.par->Last()){
2815 if (tmpcursor.par->Next()) {
2816 tmpcursor.par = tmpcursor.par->Next();
2822 SetCursor(tmpcursor.par, tmpcursor.pos);
2823 if (cursor.par->table) {
2824 int cell = NumberOfCell(cursor.par, cursor.pos);
2825 while (cursor.par->table->IsContRow(cell) &&
2826 !cursor.par->table->ShouldBeVeryLastCell(cell)) {
2828 while (tmpcursor.pos < tmpcursor.par->Last()
2829 && !tmpcursor.par->IsNewline(tmpcursor.pos))
2832 if (tmpcursor.pos == tmpcursor.par->Last()){
2833 if (tmpcursor.par->Next()) {
2834 tmpcursor.par = tmpcursor.par->Next();
2840 SetCursor(tmpcursor.par, tmpcursor.pos);
2841 cell = NumberOfCell(cursor.par, cursor.pos);
2847 /* -------> Skip initial whitespace at end of word and move cursor to *start*
2848 of prior word, not to end of next prior word. */
2850 void LyXText::CursorLeftOneWord() const
2852 // treat HFills, floats and Insets as words
2853 LyXCursor tmpcursor = cursor;
2854 while (tmpcursor.pos
2855 && (tmpcursor.par->IsSeparator(tmpcursor.pos - 1)
2856 || tmpcursor.par->IsKomma(tmpcursor.pos - 1))
2857 && !(tmpcursor.par->IsHfill(tmpcursor.pos - 1)
2858 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2859 || tmpcursor.par->IsInset(tmpcursor.pos - 1)))
2863 && (tmpcursor.par->IsInset(tmpcursor.pos - 1)
2864 || tmpcursor.par->IsFloat(tmpcursor.pos - 1)
2865 || tmpcursor.par->IsHfill(tmpcursor.pos - 1))) {
2867 } else if (!tmpcursor.pos) {
2868 if (tmpcursor.par->Previous()){
2869 tmpcursor.par = tmpcursor.par->Previous();
2870 tmpcursor.pos = tmpcursor.par->Last();
2872 } else { // Here, tmpcursor != 0
2873 while (tmpcursor.pos > 0 &&
2874 tmpcursor.par->IsWord(tmpcursor.pos-1) )
2877 SetCursor(tmpcursor.par, tmpcursor.pos);
2880 /* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
2883 void LyXText::SelectWord()
2885 /* Move cursor to the beginning, when not already there. */
2887 && !cursor.par->IsSeparator(cursor.pos-1)
2888 && !cursor.par->IsKomma(cursor.pos-1) )
2889 CursorLeftOneWord();
2891 /* set the sel cursor */
2892 sel_cursor = cursor;
2894 while ( cursor.pos < cursor.par->Last()
2895 && !cursor.par->IsSeparator(cursor.pos)
2896 && !cursor.par->IsKomma(cursor.pos) )
2898 SetCursor( cursor.par, cursor.pos );
2900 /* finally set the selection */
2905 /* -------> Select the word currently under the cursor when:
2906 1: no selection is currently set,
2907 2: the cursor is not at the borders of the word. */
2909 int LyXText::SelectWordWhenUnderCursor()
2911 if ( selection ) return 0;
2912 if ( cursor.pos < cursor.par->Last()
2913 && !cursor.par->IsSeparator(cursor.pos)
2914 && !cursor.par->IsKomma(cursor.pos)
2916 && !cursor.par->IsSeparator(cursor.pos -1)
2917 && !cursor.par->IsKomma(cursor.pos -1) ) {
2925 // This function is only used by the spellchecker for NextWord().
2926 // It doesn't handle LYX_ACCENTs and probably never will.
2927 char * LyXText::SelectNextWord(float & value)
2929 LyXParagraph * tmppar = cursor.par;
2931 // If this is not the very first word, skip rest of
2932 // current word because we are probably in the middle
2933 // of a word if there is text here.
2934 if (cursor.pos || cursor.par->previous) {
2935 while (cursor.pos < cursor.par->Last()
2936 && cursor.par->IsLetter(cursor.pos))
2939 // Now, skip until we have real text (will jump paragraphs)
2940 while ((cursor.par->Last() > cursor.pos
2941 && (!cursor.par->IsLetter(cursor.pos)
2942 || cursor.par->getFont(cursor.pos).latex() == LyXFont::ON))
2943 || (cursor.par->Last() == cursor.pos
2944 && cursor.par->Next())){
2945 if (cursor.pos == cursor.par->Last()) {
2946 cursor.par = cursor.par->Next();
2953 // Update the value if we changed paragraphs
2954 if (cursor.par != tmppar){
2955 SetCursor(cursor.par, cursor.pos);
2956 value = float(cursor.y)/float(height);
2959 /* Start the selection from here */
2960 sel_cursor = cursor;
2964 /* and find the end of the word
2965 (optional hyphens are part of a word) */
2966 while (cursor.pos < cursor.par->Last()
2967 && (cursor.par->IsLetter(cursor.pos))
2968 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET &&
2969 cursor.par->GetInset(cursor.pos) != 0 &&
2970 cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 &&
2974 // Finally, we copy the word to a string and return it
2977 if (sel_cursor.pos < cursor.pos) {
2978 str = new char [cursor.pos - sel_cursor.pos + 2];
2979 LyXParagraph::size_type i, j;
2980 for (i = sel_cursor.pos, j = 0; i < cursor.pos; ++i) {
2981 if (cursor.par->GetChar(i) != LyXParagraph::META_INSET)
2982 str[j++] = cursor.par->GetChar(i);
2990 // This one is also only for the spellchecker
2991 void LyXText::SelectSelectedWord()
2993 /* move cursor to the beginning */
2994 SetCursor(sel_cursor.par, sel_cursor.pos);
2996 /* set the sel cursor */
2997 sel_cursor = cursor;
3001 /* now find the end of the word */
3002 while (cursor.pos < cursor.par->Last()
3003 && (cursor.par->IsLetter(cursor.pos)
3004 || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET &&
3005 cursor.par->GetInset(cursor.pos) != 0 &&
3006 cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 &&
3010 SetCursor(cursor.par, cursor.pos);
3012 /* finally set the selection */
3017 /* -------> Delete from cursor up to the end of the current or next word. */
3018 void LyXText::DeleteWordForward()
3020 LyXCursor tmpcursor = cursor;
3022 if (!cursor.par->Last())
3025 /* -------> Skip initial non-word stuff. */
3026 while ( cursor.pos < cursor.par->Last()
3027 && (cursor.par->IsSeparator(cursor.pos)
3028 || cursor.par->IsKomma(cursor.pos)) )
3031 SetCursorIntern(cursor.par, cursor.pos);
3032 selection = True; // to avoid deletion
3033 CursorRightOneWord();
3034 sel_cursor = cursor;
3038 /* -----> Great, CutSelection() gets rid of multiple spaces. */
3044 /* -------> Delete from cursor to start of current or prior word. */
3045 void LyXText::DeleteWordBackward()
3047 LyXCursor tmpcursor = cursor;
3048 if (!cursor.par->Last())
3051 selection = true; // to avoid deletion
3052 CursorLeftOneWord();
3053 sel_cursor = cursor;
3061 /* -------> Kill to end of line. */
3062 void LyXText::DeleteLineForward()
3064 LyXCursor tmpcursor = cursor;
3065 if (!cursor.par->Last())
3069 sel_cursor = cursor;
3072 if (selection == false) {
3073 DeleteWordForward();
3081 // Change the case of a word at cursor position. The meaning of action
3083 // 0 change to lowercase
3084 // 1 capitalize word
3085 // 2 change to uppercase
3086 // This function directly manipulates LyXParagraph::text because there
3087 // is no LyXParagraph::SetChar currently. I did what I could to ensure
3088 // that it is correct. I guess part of it should be moved to
3089 // LyXParagraph, but it will have to change for 1.1 anyway. At least
3090 // it does not access outside of the allocated array as the older
3091 // version did. (JMarc)
3092 void LyXText::ChangeWordCase(LyXText::TextCase action)
3094 LyXParagraph * tmppar = cursor.par->ParFromPos(cursor.pos);
3096 SetUndo(Undo::FINISH, tmppar->previous, tmppar->next);
3098 LyXParagraph::size_type tmppos =
3099 cursor.par->PositionInParFromPos(cursor.pos);
3100 while (tmppos < tmppar->size()) {
3101 unsigned char c = tmppar->text[tmppos];
3102 if (IsKommaChar(c) || IsLineSeparatorChar(c))
3104 if (c != LyXParagraph::META_INSET) {
3106 case text_lowercase:
3109 case text_capitalization:
3111 action = text_lowercase;
3113 case text_uppercase:
3119 tmppar->text[tmppos] = c;
3122 CheckParagraph(tmppar, tmppos);
3123 CursorRightOneWord();
3127 void LyXText::Delete()
3129 // this is a very easy implementation
3131 LyXCursor old_cursor = cursor;
3132 int old_cur_par_id = old_cursor.par->id();
3133 int old_cur_par_prev_id = old_cursor.par->previous ?
3134 old_cursor.par->previous->id() : 0;
3136 // just move to the right
3137 CursorRightIntern();
3139 // This check is not very good...
3140 // The CursorRightIntern calls DeleteEmptyParagrapgMechanism
3141 // and that can very well delete the par or par->previous in
3142 // old_cursor. Will a solution where we compare paragraph id's
3145 if ((cursor.par->previous ? cursor.par->previous->id() : 0)
3146 == old_cur_par_prev_id
3147 && cursor.par->id() != old_cur_par_id)
3148 return; // delete-empty-paragraph-mechanism has done it
3150 if (cursor.par->previous == old_cursor.par->previous
3151 && cursor.par != old_cursor.par)
3152 return; // delete-empty-paragraph-mechanism has done it
3154 // if you had success make a backspace
3155 if (old_cursor.par != cursor.par || old_cursor.pos != cursor.pos) {
3156 LyXCursor tmpcursor = cursor;
3157 cursor = old_cursor; // to make sure undo gets the right cursor position
3158 SetUndo(Undo::DELETE,
3159 cursor.par->ParFromPos(cursor.pos)->previous,
3160 cursor.par->ParFromPos(cursor.pos)->next);
3167 void LyXText::Backspace()
3169 LyXParagraph * tmppar;
3170 Row * tmprow, * row;
3174 /* table stuff -- begin */
3175 if (cursor.par->table) {
3179 /* table stuff -- end */
3181 LyXFont rawtmpfont = current_font;
3182 LyXFont realtmpfont = real_current_font;
3184 // Get the font that is used to calculate the baselineskip
3185 int const lastpos = cursor.par->Last();
3186 LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1);
3188 if (cursor.pos == 0) {
3189 // we may paste some paragraphs
3191 // is it an empty paragraph?
3194 || (lastpos == 1 && cursor.par->IsSeparator(0)))
3195 && !(cursor.par->Next()
3196 && cursor.par->footnoteflag ==
3197 LyXParagraph::NO_FOOTNOTE
3198 && cursor.par->Next()->footnoteflag ==
3199 LyXParagraph::OPEN_FOOTNOTE)) {
3201 if (cursor.par->previous) {
3202 tmppar = cursor.par->previous->FirstPhysicalPar();
3203 if (cursor.par->GetLayout() == tmppar->GetLayout()
3204 && cursor.par->footnoteflag == tmppar->footnoteflag
3205 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3207 tmppar->line_bottom = cursor.par->line_bottom;
3208 tmppar->added_space_bottom = cursor.par->added_space_bottom;
3209 tmppar->pagebreak_bottom = cursor.par->pagebreak_bottom;
3214 // the layout things can change the height of a row !
3215 tmpheight = cursor.row->height;
3216 SetHeightOfRow(cursor.row);
3217 if (cursor.row->height != tmpheight) {
3218 refresh_y = cursor.y - cursor.row->baseline;
3219 refresh_row = cursor.row;
3220 status = LyXText::NEED_MORE_REFRESH;
3225 if (cursor.par->ParFromPos(cursor.pos)->previous){
3226 SetUndo(Undo::DELETE,
3227 cursor.par->ParFromPos(cursor.pos)->previous->previous,
3228 cursor.par->ParFromPos(cursor.pos)->next);
3230 tmppar = cursor.par;
3231 tmprow = cursor.row;
3233 /* Pasting is not allowed, if the paragraphs have different
3234 layout. I think it is a real bug of all other
3235 word processors to allow it. It confuses the user.
3236 Even so with a footnote paragraph and a non-footnote
3237 paragraph. I will not allow pasting in this case,
3238 because the user would be confused if the footnote behaves
3239 different wether it is open or closed.
3241 Correction: Pasting is always allowed with standard-layout
3243 if (cursor.par != tmppar
3244 && (cursor.par->GetLayout() == tmppar->GetLayout()
3245 || !tmppar->GetLayout())
3246 && cursor.par->footnoteflag == tmppar->footnoteflag
3247 /* table stuff -- begin*/
3248 && !cursor.par->table /* no pasting of tables */
3249 /* table stuff -- end*/
3250 && cursor.par->GetAlign() == tmppar->GetAlign()) {
3252 cursor.par->PasteParagraph();
3255 cursor.par->IsSeparator(cursor.pos - 1)))
3256 cursor.par->InsertChar(cursor.pos, ' ');
3261 status = LyXText::NEED_MORE_REFRESH;
3262 refresh_row = cursor.row;
3263 refresh_y = cursor.y - cursor.row->baseline;
3265 // remove the lost paragraph
3266 RemoveParagraph(tmprow);
3269 AppendParagraph(cursor.row);
3270 UpdateCounters(cursor.row);
3272 // the row may have changed, block, hfills etc.
3273 SetCursor(cursor.par, cursor.pos);
3276 /* this is the code for a normal backspace, not pasting
3278 SetUndo(Undo::DELETE,
3279 cursor.par->ParFromPos(cursor.pos)->previous,
3280 cursor.par->ParFromPos(cursor.pos)->next);
3283 // some insets are undeletable here
3284 if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) {
3285 if (!cursor.par->GetInset(cursor.pos)->Deletable())
3287 // force complete redo when erasing display insets
3288 // this is a cruel mathod but save..... Matthias
3289 if (cursor.par->GetInset(cursor.pos)->display()){
3290 cursor.par->Erase(cursor.pos);
3297 y = cursor.y - row->baseline;
3298 LyXParagraph::size_type z;
3299 /* remember that a space at the end of a row doesnt count
3300 * when calculating the fill */
3301 if (cursor.pos < RowLast(row) ||
3302 !cursor.par->IsLineSeparator(cursor.pos)) {
3303 row->fill += SingleWidth(cursor.par, cursor.pos);
3306 /* some special code when deleting a newline. This is similar
3307 * to the behavior when pasting paragraphs */
3308 if (cursor.pos && cursor.par->IsNewline(cursor.pos)) {
3309 cursor.par->Erase(cursor.pos);
3310 // refresh the positions
3312 while (tmprow->next && tmprow->next->par == row->par) {
3313 tmprow = tmprow->next;
3316 if (cursor.par->IsLineSeparator(cursor.pos - 1))
3319 if (cursor.pos < cursor.par->Last() && !cursor.par->IsSeparator(cursor.pos)) {
3320 cursor.par->InsertChar(cursor.pos, ' ');
3321 // refresh the positions
3323 while (tmprow->next && tmprow->next->par == row->par) {
3324 tmprow = tmprow->next;
3329 cursor.par->Erase(cursor.pos);
3331 // refresh the positions
3333 while (tmprow->next && tmprow->next->par == row->par) {
3334 tmprow = tmprow->next;
3338 #ifndef FIX_DOUBLE_SPACE
3339 // delete superfluous blanks
3340 if (cursor.pos < cursor.par->Last() - 1 &&
3341 (cursor.par->IsLineSeparator(cursor.pos))) {
3343 if (cursor.pos == BeginningOfMainBody(cursor.par)
3345 || cursor.par->IsLineSeparator(cursor.pos - 1)) {
3346 cursor.par->Erase(cursor.pos);
3347 // refresh the positions
3349 while (tmprow->next &&
3350 tmprow->next->par == row->par) {
3351 tmprow = tmprow->next;
3354 if (cursor.pos) // move one character left
3360 // delete newlines at the beginning of paragraphs
3361 while (cursor.par->Last() &&
3362 cursor.par->IsNewline(cursor.pos) &&
3363 cursor.pos == BeginningOfMainBody(cursor.par)) {
3364 cursor.par->Erase(cursor.pos);
3365 // refresh the positions
3367 while (tmprow->next &&
3368 tmprow->next->par == row->par) {
3369 tmprow = tmprow->next;
3375 // is there a break one row above
3376 if (row->previous && row->previous->par == row->par) {
3377 z = NextBreakPoint(row->previous, paperwidth);
3378 if ( z >= row->pos) {
3381 tmprow = row->previous;
3383 // maybe the current row is now empty
3384 if (row->pos >= row->par->Last()) {
3389 BreakAgainOneRow(row);
3390 if (row->next && row->next->par == row->par)
3391 need_break_row = row->next;
3396 // set the dimensions of the row above
3397 y -= tmprow->height;
3398 tmprow->fill = Fill(tmprow, paperwidth);
3399 SetHeightOfRow(tmprow);
3402 refresh_row = tmprow;
3403 status = LyXText::NEED_MORE_REFRESH;
3404 current_font = rawtmpfont;
3405 real_current_font = realtmpfont;
3406 SetCursor(cursor.par, cursor.pos, false);
3407 // check, whether the last character's font has changed.
3408 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3409 if (rawparfont != rawtmpfont)
3410 RedoHeightOfParagraph(cursor);
3415 // break the cursor row again
3416 z = NextBreakPoint(row, paperwidth);
3418 if (z != RowLast(row) ||
3419 (row->next && row->next->par == row->par &&
3420 RowLast(row) == row->par->Last() - 1)){
3422 /* it can happen that a paragraph loses one row
3423 * without a real breakup. This is when a word
3424 * is to long to be broken. Well, I don t care this
3426 if (row->next && row->next->par == row->par &&
3427 RowLast(row) == row->par->Last() - 1)
3428 RemoveRow(row->next);
3432 status = LyXText::NEED_MORE_REFRESH;
3434 BreakAgainOneRow(row);
3435 current_font = rawtmpfont;
3436 real_current_font = realtmpfont;
3437 SetCursor(cursor.par, cursor.pos, false);
3438 // cursor MUST be in row now
3440 if (row->next && row->next->par == row->par)
3441 need_break_row = row->next;
3445 // set the dimensions of the row
3446 row->fill = Fill(row, paperwidth);
3447 int tmpheight = row->height;
3448 SetHeightOfRow(row);
3449 if (tmpheight == row->height)
3450 status = LyXText::NEED_VERY_LITTLE_REFRESH;
3452 status = LyXText::NEED_MORE_REFRESH;
3455 current_font = rawtmpfont;
3456 real_current_font = realtmpfont;
3457 SetCursor(cursor.par, cursor.pos, false);
3461 // restore the current font
3462 // That is what a user expects!
3463 current_font = rawtmpfont;
3464 real_current_font = realtmpfont;
3466 // check, wether the last characters font has changed.
3467 rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1);
3468 if (rawparfont != rawtmpfont) {
3469 RedoHeightOfParagraph(cursor);
3471 // now the special right address boxes
3472 if (textclasslist.Style(parameters->textclass,
3473 cursor.par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) {
3474 RedoDrawingOfParagraph(cursor);
3480 void LyXText::GetVisibleRow(LyXScreen & scr, int offset,
3481 Row * row_ptr, long y)
3483 /* returns a printed row */
3484 LyXDirection direction = GetParDirection(row_ptr->par);
3485 LyXParagraph::size_type vpos, pos, pos_end;
3487 int y_top, y_bottom;
3488 float fill_separator, fill_hfill, fill_label_hfill;
3489 LyXParagraph * par, * firstpar;
3492 if (row_ptr->height <= 0) {
3493 lyxerr << "LYX_ERROR: row.height: " << row_ptr->height << endl;
3496 PrepareToPrint(row_ptr, x, fill_separator,
3497 fill_hfill, fill_label_hfill);
3499 /* initialize the pixmap */
3501 scr.fillRectangle(gc_clear,
3502 0, offset, paperwidth, row_ptr->height);
3503 // check for NOT FAST SELECTION
3504 if (!fast_selection && !mono_video && selection) {
3505 /* selection code */
3506 if (sel_start_cursor.row == row_ptr &&
3507 sel_end_cursor.row == row_ptr) {
3508 if (sel_start_cursor.x < sel_end_cursor.x)
3509 scr.fillRectangle(gc_selection, sel_start_cursor.x,
3511 sel_end_cursor.x - sel_start_cursor.x,
3514 scr.fillRectangle(gc_selection, sel_end_cursor.x,
3516 sel_start_cursor.x - sel_end_cursor.x,
3519 else if (sel_start_cursor.row == row_ptr) {
3520 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3521 scr.fillRectangle(gc_selection, sel_start_cursor.x,
3523 paperwidth - sel_start_cursor.x,
3526 scr.fillRectangle(gc_selection, 0, offset,
3527 sel_start_cursor.x, row_ptr->height);
3528 } else if (sel_end_cursor.row == row_ptr) {
3529 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3530 scr.fillRectangle(gc_selection, 0, offset,
3531 sel_end_cursor.x, row_ptr->height);
3533 scr.fillRectangle(gc_selection, sel_end_cursor.x,
3535 paperwidth - sel_end_cursor.x,
3537 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
3538 scr.fillRectangle(gc_selection, 0, offset,
3539 paperwidth, row_ptr->height);
3542 } // end of NOT FAST SELECTION code
3544 if (row_ptr->par->appendix){
3545 scr.drawVerticalLine(gc_math, 1, offset, offset+row_ptr->height);
3546 scr.drawVerticalLine(gc_math, paperwidth-2 , offset, offset+row_ptr->height);
3549 if (row_ptr->par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
3550 /* draw a marker at the left margin! */
3551 LyXFont font = GetFont(row_ptr->par, 0);
3552 int asc = font.maxAscent();
3553 int x = (LYX_PAPER_MARGIN - font.width('|')) / 2;
3554 int y1 = (offset + row_ptr->baseline);
3555 int y2 = (offset + row_ptr->baseline) - asc;
3557 scr.drawVerticalLine(gc_minipage, x, y1, y2);
3559 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3560 LyXFont font(LyXFont::ALL_SANE);
3561 font.setSize(LyXFont::SIZE_FOOTNOTE);
3562 font.setColor(LyXFont::RED);
3564 int box_x = LYX_PAPER_MARGIN;
3565 box_x += font.textWidth(" wide-tab ", 10);
3566 if (row_ptr->previous &&
3567 row_ptr->previous->par->footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
3569 switch (row_ptr->par->footnotekind) {
3570 case LyXParagraph::MARGIN:
3573 case LyXParagraph::FIG:
3576 case LyXParagraph::TAB:
3579 case LyXParagraph::WIDE_FIG:
3582 case LyXParagraph::WIDE_TAB:
3585 case LyXParagraph::ALGORITHM:
3588 case LyXParagraph::FOOTNOTE:
3593 // Determine background color.
3594 gc_type back = gc_lighted;
3598 scr.fillRectangle(back, LYX_PAPER_MARGIN, offset+1,
3599 box_x - LYX_PAPER_MARGIN,
3600 int(font.maxAscent())+
3601 int(font.maxDescent()));
3603 scr.drawLine(gc_foot,
3606 paperwidth - 2*LYX_PAPER_MARGIN);
3608 scr.drawString(font, fs,
3609 offset + int(font.maxAscent())+1,
3611 scr.drawVerticalLine(gc_foot,
3615 + int(font.maxAscent())+
3616 int(font.maxDescent()));
3618 scr.drawLine(gc_foot,
3620 + int(font.maxAscent())
3621 + int(font.maxDescent()) + 1,
3622 LYX_PAPER_MARGIN, box_x - LYX_PAPER_MARGIN);
3625 /* draw the open floats in a red box */
3626 scr.drawVerticalLine(gc_foot,
3628 offset, offset + row_ptr->height);
3630 scr.drawVerticalLine(gc_foot,
3631 paperwidth - LYX_PAPER_MARGIN,
3633 offset + row_ptr->height);
3636 if (row_ptr->previous &&
3637 row_ptr->previous->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3638 LyXFont font(LyXFont::ALL_SANE);
3639 font.setSize(LyXFont::SIZE_FOOTNOTE);
3641 int box_x = LYX_PAPER_MARGIN;
3642 box_x += font.textWidth(" wide-tab ", 10);
3644 scr.drawLine(gc_foot,
3647 paperwidth - LYX_PAPER_MARGIN - box_x);
3651 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
3652 row_ptr->par->GetLayout());
3653 firstpar = row_ptr->par->FirstPhysicalPar();
3656 y_bottom = row_ptr->height;
3658 /* is it a first row? */
3659 if (row_ptr->pos == 0
3660 && row_ptr->par == firstpar) {
3662 /* start of appendix? */
3663 if (row_ptr->par->start_of_appendix){
3664 scr.drawLine(gc_math,
3669 /* think about the margins */
3670 if (!row_ptr->previous)
3671 y_top += LYX_PAPER_MARGIN;
3673 if (row_ptr->par->pagebreak_top){ /* draw a top pagebreak */
3674 scr.drawOnOffLine(offset + y_top + 2 * DefaultHeight(),
3676 y_top += 3 * DefaultHeight();
3679 if (row_ptr->par->added_space_top.kind() == VSpace::VFILL) {
3680 /* draw a vfill top */
3681 scr.drawLine(gc_fill,
3683 0, LYX_PAPER_MARGIN);
3684 scr.drawLine(gc_fill,
3685 offset + y_top + 3 * DefaultHeight(),
3686 0, LYX_PAPER_MARGIN);
3687 scr.drawVerticalOnOffLine(LYX_PAPER_MARGIN / 2,
3689 offset + y_top + 3 *
3692 y_top += 3 * DefaultHeight();
3695 /* think about user added space */
3696 y_top += int(row_ptr->par->added_space_top.inPixels());
3698 /* think about the parskip */
3699 /* some parskips VERY EASY IMPLEMENTATION */
3700 if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) {
3701 if (layout.latextype == LATEX_PARAGRAPH
3702 && firstpar->GetDepth() == 0
3703 && firstpar->Previous())
3704 y_top += parameters->getDefSkip().inPixels();
3705 else if (firstpar->Previous()
3706 && textclasslist.Style(parameters->textclass,
3707 firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH
3708 && firstpar->Previous()->GetDepth() == 0)
3709 // is it right to use defskip here, too? (AS)
3710 y_top += parameters->getDefSkip().inPixels();
3713 if (row_ptr->par->line_top) { /* draw a top line */
3714 y_top += GetFont(row_ptr->par, 0).ascent('x');
3716 scr.drawThickLine(offset + y_top,
3718 y_top += GetFont(row_ptr->par, 0).ascent('x');
3721 /* should we print a label? */
3722 if (layout.labeltype >= LABEL_STATIC
3723 && (layout.labeltype != LABEL_STATIC
3724 || layout.latextype != LATEX_ENVIRONMENT
3725 || row_ptr->par->IsFirstInSequence())) {
3726 font = GetFont(row_ptr->par, -2);
3727 if (!row_ptr->par->GetLabestring().empty()) {
3729 string tmpstring = row_ptr->par->GetLabestring();
3731 if (layout.labeltype == LABEL_COUNTER_CHAPTER) {
3732 if (parameters->secnumdepth >= 0){
3733 /* this is special code for the chapter layout. This is printed in
3734 * an extra row and has a pagebreak at the top. */
3735 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue())
3736 + int(layout.parsep) * DefaultHeight();
3737 if (direction == LYX_DIR_RIGHT_TO_LEFT)
3738 tmpx = paperwidth - LeftMargin(row_ptr) -
3739 font.stringWidth(tmpstring);
3740 scr.drawString(font, tmpstring,
3741 offset + row_ptr->baseline
3742 - row_ptr->ascent_of_text - maxdesc,
3746 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3747 tmpx = x - font.stringWidth(layout.labelsep)
3748 - font.stringWidth(tmpstring);
3750 tmpx = paperwidth - LeftMargin(row_ptr)
3751 + font.stringWidth(layout.labelsep);
3752 if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
3753 LyXFont font(LyXFont::ALL_SANE);
3754 font.setSize(LyXFont::SIZE_SMALL);
3755 tmpx += font.textWidth("Mwide-figM", 10);
3759 scr.drawString(font, tmpstring,
3760 offset + row_ptr->baseline, int(tmpx));
3763 /* the labels at the top of an environment. More or less for bibliography */
3764 } else if (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
3765 layout.labeltype == LABEL_BIBLIO ||
3766 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
3767 if (row_ptr->par->IsFirstInSequence()) {
3768 font = GetFont(row_ptr->par, -2);
3769 if (!row_ptr->par->GetLabestring().empty()) {
3770 string tmpstring = row_ptr->par->GetLabestring();
3772 maxdesc = int(font.maxDescent() * layout.spacing.getValue() * parameters->spacing.getValue()
3773 + (layout.labelbottomsep * DefaultHeight()));
3776 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){
3777 tmpx = ( ((direction == LYX_DIR_LEFT_TO_RIGHT)
3778 ? x : LeftMargin(row_ptr) )
3779 + paperwidth - RightMargin(row_ptr) ) / 2;
3780 tmpx -= (font.stringWidth(tmpstring)/2);
3781 } else if (direction == LYX_DIR_RIGHT_TO_LEFT)
3782 tmpx = paperwidth - LeftMargin(row_ptr) -
3783 font.stringWidth(tmpstring);
3785 scr.drawString(font, tmpstring,
3786 offset + row_ptr->baseline
3787 - row_ptr->ascent_of_text - maxdesc,
3792 if (layout.labeltype == LABEL_BIBLIO) { // ale970302
3793 if (row_ptr->par->bibkey) {
3794 font = GetFont(row_ptr->par, -1);
3795 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3796 tmpx = x - font.stringWidth(layout.labelsep)
3797 - row_ptr->par->bibkey->Width(font);
3799 tmpx = paperwidth - LeftMargin(row_ptr)
3800 + font.stringWidth(layout.labelsep);
3801 row_ptr->par->bibkey->Draw(font, scr,
3802 offset + row_ptr->baseline,
3808 /* is it a last row? */
3809 par = row_ptr->par->LastPhysicalPar();
3810 if (row_ptr->par->ParFromPos(RowLast(row_ptr) + 1) == par
3811 && (!row_ptr->next || row_ptr->next->par != row_ptr->par)) {
3813 /* think about the margins */
3815 y_bottom -= LYX_PAPER_MARGIN;
3817 /* draw a bottom pagebreak */
3818 if (firstpar->pagebreak_bottom) {
3819 scr.drawOnOffLine(offset + y_bottom - 2 *
3822 y_bottom -= 3 * DefaultHeight();
3825 if (firstpar->added_space_bottom.kind() == VSpace::VFILL) {
3826 /* draw a vfill bottom */
3827 scr.drawLine(gc_fill,
3828 offset + y_bottom - 3 * DefaultHeight(),
3829 0, LYX_PAPER_MARGIN);
3830 scr.drawLine(gc_fill, offset + y_bottom - 2,
3831 0, LYX_PAPER_MARGIN);
3832 scr.drawVerticalOnOffLine(LYX_PAPER_MARGIN / 2,
3833 offset + y_bottom - 3 * DefaultHeight(),
3834 offset + y_bottom - 2
3836 y_bottom -= 3* DefaultHeight();
3839 /* think about user added space */
3840 y_bottom -= int(firstpar->added_space_bottom.inPixels());
3842 if (firstpar->line_bottom) {
3843 /* draw a bottom line */
3844 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3846 scr.drawThickLine(offset + y_bottom,
3848 y_bottom -= GetFont(par, par->Last() - 1).ascent('x');
3852 /* draw the text in the pixmap */
3853 pos_end = RowLast(row_ptr);
3855 vpos = row_ptr->pos;
3856 /* table stuff -- begin*/
3857 if (row_ptr->par->table) {
3859 int cell = NumberOfCell(row_ptr->par, row_ptr->pos);
3861 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3863 while (vpos <= pos_end) {
3864 pos = vis2log(vpos);
3865 if (row_ptr->par->IsNewline(pos)) {
3867 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
3868 /* draw the table lines, still very simple */
3869 on_off = !row_ptr->par->table->TopLine(cell);
3871 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
3872 !row_ptr->par->table->IsContRow(cell))
3873 scr.drawTableLine(offset + row_ptr->baseline -
3874 row_ptr->ascent_of_text,
3875 int(x_old), int(x - x_old), on_off);
3876 on_off = !row_ptr->par->table->BottomLine(cell);
3877 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
3878 row_ptr->par->table->VeryLastRow(cell))
3879 scr.drawTableLine(offset + y_bottom - 1,
3880 int(x_old), int(x - x_old), on_off);
3881 on_off = !row_ptr->par->table->LeftLine(cell);
3883 scr.drawVerticalTableLine(int(x_old),
3884 offset + row_ptr->baseline -
3885 row_ptr->ascent_of_text,
3886 offset + y_bottom - 1,
3888 on_off = !row_ptr->par->table->RightLine(cell);
3890 scr.drawVerticalTableLine(int(x) -
3891 row_ptr->par->table->AdditionalWidth(cell),
3892 offset + row_ptr->baseline -
3893 row_ptr->ascent_of_text,
3894 offset + y_bottom - 1,
3897 /* take care about the alignment and other spaces */
3899 x += row_ptr->par->table->GetBeginningOfTextInCell(cell);
3900 if (row_ptr->par->table->IsFirstCell(cell))
3901 --cell; // little hack, sorry
3903 } else if (row_ptr->par->IsHfill(pos)) {
3906 scr.drawVerticalLine(gc_fill, int(x),
3907 offset + row_ptr->baseline - DefaultHeight()/2,
3908 offset + row_ptr->baseline);
3912 if (row_ptr->par->IsSeparator(pos)) {
3914 x+= SingleWidth(row_ptr->par, pos);
3915 /* -------> Only draw protected spaces when not in
3916 * free-spacing mode. */
3917 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
3918 scr.drawVerticalLine(gc_fill, int(tmpx),
3919 offset + row_ptr->baseline - 3,
3920 offset + row_ptr->baseline - 1);
3921 scr.drawLine(gc_fill,
3922 offset + row_ptr->baseline - 1,
3925 scr.drawVerticalLine(gc_fill, int(x-2),
3926 offset + row_ptr->baseline - 3,
3927 offset + row_ptr->baseline - 1);
3928 /* what about underbars? */
3929 font = GetFont(row_ptr->par, pos);
3930 if (font.underbar() == LyXFont::ON
3931 && font.latex() != LyXFont::ON) {
3932 scr.drawLine(gc_copy,
3934 row_ptr->baseline + 2,
3941 Draw(row_ptr, vpos, scr, offset, x);
3945 /* do not forget the very last cell. This has no NEWLINE so
3946 * ignored by the code above*/
3947 if (cell == row_ptr->par->table->GetNumberOfCells()-1){
3948 x = x_old + row_ptr->par->table->WidthOfColumn(cell);
3949 on_off = !row_ptr->par->table->TopLine(cell);
3951 !row_ptr->par->table->TopAlreadyDrawed(cell)) &&
3952 !row_ptr->par->table->IsContRow(cell))
3954 scr.drawTableLine(offset + row_ptr->baseline -
3955 row_ptr->ascent_of_text,
3956 int(x_old), int(x - x_old), on_off);
3957 on_off = !row_ptr->par->table->BottomLine(cell);
3958 if ((!on_off && !row_ptr->par->table->RowHasContRow(cell)) ||
3959 row_ptr->par->table->VeryLastRow(cell))
3961 scr.drawTableLine(offset + y_bottom - 1,
3962 int(x_old), int(x - x_old), on_off);
3963 on_off = !row_ptr->par->table->LeftLine(cell);
3965 scr.drawVerticalTableLine(int(x_old),
3966 offset + row_ptr->baseline -
3967 row_ptr->ascent_of_text,
3968 offset + y_bottom - 1,
3970 on_off = !row_ptr->par->table->RightLine(cell);
3972 scr.drawVerticalTableLine(int(x) -
3973 row_ptr->par->table->AdditionalWidth(cell),
3974 offset + row_ptr->baseline -
3975 row_ptr->ascent_of_text,
3976 offset + y_bottom - 1,
3980 /* table stuff -- end*/
3981 LyXParagraph::size_type main_body =
3982 BeginningOfMainBody(row_ptr->par);
3983 if (main_body > 0 &&
3984 (main_body-1 > pos_end ||
3985 !row_ptr->par->IsLineSeparator(main_body-1)))
3988 while (vpos <= pos_end) {
3989 pos = vis2log(vpos);
3990 if (main_body > 0 && pos == main_body-1) {
3991 x += fill_label_hfill
3992 + GetFont(row_ptr->par, -2).stringWidth(layout.labelsep)
3993 - SingleWidth(row_ptr->par, main_body-1);
3996 if (row_ptr->par->IsHfill(pos)) {
3998 scr.drawVerticalLine(gc_fill, int(x),
3999 offset + row_ptr->baseline - DefaultHeight()/2,
4000 offset + row_ptr->baseline);
4001 if (HfillExpansion(row_ptr, pos)) {
4002 if (pos >= main_body) {
4003 scr.drawOnOffLine(offset + row_ptr->baseline -
4009 scr.drawOnOffLine(offset + row_ptr->baseline -
4012 int(fill_label_hfill));
4013 x += fill_label_hfill;
4015 scr.drawVerticalLine(gc_fill, int(x),
4016 offset + row_ptr->baseline -
4018 offset + row_ptr->baseline);
4023 if (row_ptr->par->IsSeparator(pos)) {
4025 x+= SingleWidth(row_ptr->par, pos);
4026 if (pos >= main_body)
4028 /* -------> Only draw protected spaces when not in
4029 * free-spacing mode. */
4030 if (row_ptr->par->GetChar(pos) == LyXParagraph::META_PROTECTED_SEPARATOR && !layout.free_spacing) {
4032 scr.drawVerticalLine(gc_fill, int(tmpx),
4033 offset + row_ptr->baseline - 3,
4034 offset + row_ptr->baseline - 1);
4035 scr.drawLine(gc_fill,
4036 offset + row_ptr->baseline - 1,
4039 scr.drawVerticalLine(gc_fill, int(x-2),
4040 offset + row_ptr->baseline - 3,
4041 offset + row_ptr->baseline - 1);
4042 /* what about underbars? */
4043 font = GetFont(row_ptr->par, pos);
4044 if (font.underbar() == LyXFont::ON
4045 && font.latex() != LyXFont::ON) {
4046 scr.drawLine(gc_copy,
4047 offset + row_ptr->baseline + 2,
4054 Draw(row_ptr, vpos, scr, offset, x);
4058 // check for FAST SELECTION
4059 if (fast_selection || mono_video) {
4062 /* selection code */
4063 if (sel_start_cursor.row == row_ptr && sel_end_cursor.row == row_ptr) {
4064 scr.fillRectangle(gc_select, sel_start_cursor.x, offset,
4065 sel_end_cursor.x - sel_start_cursor.x,
4067 } else if (sel_start_cursor.row == row_ptr) {
4068 scr.fillRectangle(gc_select, sel_start_cursor.x, offset,
4069 paperwidth - sel_start_cursor.x,
4071 } else if (sel_end_cursor.row == row_ptr) {
4072 scr.fillRectangle(gc_select, 0, offset,
4075 } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) {
4076 scr.fillRectangle(gc_select, 0, offset,
4077 paperwidth, row_ptr->height);
4082 // end of FAST SELECTION code
4087 int LyXText::DefaultHeight() const
4089 LyXFont font(LyXFont::ALL_SANE);
4090 return int(font.maxAscent() + font.maxDescent() * 1.5);
4094 /* returns the column near the specified x-coordinate of the row
4095 * x is set to the real beginning of this column */
4096 int LyXText::GetColumnNearX(Row * row, int & x) const
4099 float fill_separator, fill_hfill, fill_label_hfill;
4101 PrepareToPrint(row, tmpx, fill_separator,
4102 fill_hfill, fill_label_hfill);
4104 LyXDirection direction = GetParDirection(row->par);
4105 LyXParagraph::size_type vc = row->pos;
4106 LyXParagraph::size_type last = RowLast(row);
4107 LyXParagraph::size_type c;
4109 LyXLayout const & layout = textclasslist.Style(parameters->textclass,
4110 row->par->GetLayout());
4111 /* table stuff -- begin */
4112 if (row->par->table) {
4113 if (row->next && row->next->par == row->par //the last row doesn't need a newline at the end
4114 && row->par->IsNewline(last))
4116 int cell = NumberOfCell(row->par, row->pos);
4119 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4121 && (c = vis2log(vc)) >= 0
4122 && tmpx + (SingleWidth(row->par, c)/2) <= x
4124 if (row->par->IsNewline(c)) {
4125 if (x_old + row->par->table->WidthOfColumn(cell) <= x){
4126 tmpx = x_old + row->par->table->WidthOfColumn(cell);
4129 tmpx += row->par->table->GetBeginningOfTextInCell(cell);
4134 tmpx += SingleWidth(row->par, c);
4139 /* table stuff -- end*/
4140 LyXParagraph::size_type main_body = BeginningOfMainBody(row->par);
4141 float last_tmpx = tmpx;
4143 if (main_body > 0 &&
4144 (main_body-1 > last ||
4145 !row->par->IsLineSeparator(main_body-1)))
4148 while (vc <= last && tmpx <= x) {
4151 if (main_body > 0 && c == main_body-1) {
4152 tmpx += fill_label_hfill +
4153 GetFont(row->par, -2).stringWidth(layout.labelsep);
4154 if (row->par->IsLineSeparator(main_body-1))
4155 tmpx -= SingleWidth(row->par, main_body-1);
4158 tmpx += SingleWidth(row->par, c);
4159 if (HfillExpansion(row, c)) {
4163 tmpx += fill_label_hfill;
4165 else if (c >= main_body
4166 && row->par->IsSeparator(c)) {
4167 tmpx+= fill_separator;
4172 if (vc > row->pos && (tmpx+last_tmpx)/2 > x) {
4177 /* make sure that a last space in a row doesnt count */
4178 if (row->pos <= last
4179 && !(!row->next || row->next->par != row->par))
4180 if (direction == LYX_DIR_LEFT_TO_RIGHT && vc > last
4181 && row->par->IsLineSeparator(vis2log(last)) ) {
4183 tmpx -= fill_separator+SingleWidth(row->par, vis2log(last));
4184 } else if (direction == LYX_DIR_RIGHT_TO_LEFT
4186 && row->par->IsLineSeparator(vis2log(row->pos)) ) {
4188 tmpx += fill_separator+SingleWidth(row->par, vis2log(row->pos));
4191 if (row->pos > last) // Row is empty?
4193 else if (vc <= last) {
4195 LyXDirection direction = GetLetterDirection(row->par , c);
4196 if (vc > row->pos && row->par->IsLineSeparator(c)
4197 && GetLetterDirection(row->par , vis2log(vc-1)) != direction)
4199 if (direction == LYX_DIR_RIGHT_TO_LEFT)
4202 c = vis2log(last)+1;
4203 if (GetLetterDirection(row->par, c-1) == LYX_DIR_RIGHT_TO_LEFT)
4207 if (!row->par->table && row->pos <= last && c > last
4208 && row->par->IsNewline(last)) {
4209 if (GetLetterDirection(row->par,last) == LYX_DIR_LEFT_TO_RIGHT)
4210 tmpx -= SingleWidth(row->par, last);
4212 tmpx += SingleWidth(row->par, last);
4222 /* turn the selection into a new environment. If there is no selection,
4223 * create an empty environment */
4224 void LyXText::InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind)
4226 /* no footnoteenvironment in a footnoteenvironment */
4227 if (cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4228 WriteAlert(_("Impossible operation"),
4229 _("You can't insert a float in a float!"),
4233 /* no marginpars in minipages */
4234 if (kind == LyXParagraph::MARGIN
4235 && cursor.par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
4236 WriteAlert(_("Impossible operation"),
4237 _("You can't insert a marginpar in a minipage!"),
4242 /* this doesnt make sense, if there is no selection */
4243 bool dummy_selection = false;
4245 sel_start_cursor = cursor; /* dummy selection */
4246 sel_end_cursor = cursor;
4247 dummy_selection = true;
4250 LyXParagraph *tmppar;
4252 if (sel_start_cursor.par->table || sel_end_cursor.par->table){
4253 WriteAlert(_("Impossible operation"), _("Cannot cut table."), _("Sorry."));
4257 /* a test to make sure there is not already a footnote
4258 * in the selection. */
4260 tmppar = sel_start_cursor.par->ParFromPos(sel_start_cursor.pos);
4262 while (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos) &&
4263 tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
4264 tmppar = tmppar->next;
4266 if (tmppar != sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)
4267 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
4268 WriteAlert(_("Impossible operation"),
4269 _("Float would include float!"),
4274 /* ok we have a selection. This is always between sel_start_cursor
4275 * and sel_end cursor */
4277 SetUndo(Undo::FINISH,
4278 sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous,
4279 sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)->next);
4281 if (sel_end_cursor.pos > 0
4282 && sel_end_cursor.par->IsLineSeparator(sel_end_cursor.pos - 1))
4283 sel_end_cursor.pos--; /* please break before a space at
4285 if (sel_start_cursor.par == sel_end_cursor.par
4286 && sel_start_cursor.pos > sel_end_cursor.pos)
4287 sel_start_cursor.pos--;
4289 sel_end_cursor.par->BreakParagraphConservative(sel_end_cursor.pos);
4291 sel_end_cursor.par = sel_end_cursor.par->Next();
4292 sel_end_cursor.pos = 0;
4294 // don't forget to insert a dummy layout paragraph if necessary
4295 if (sel_start_cursor.par->GetLayout() != sel_end_cursor.par->layout){
4296 sel_end_cursor.par->BreakParagraphConservative(0);
4297 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4298 sel_end_cursor.par = sel_end_cursor.par->next;
4301 sel_end_cursor.par->layout = LYX_DUMMY_LAYOUT;
4303 cursor = sel_end_cursor;
4305 /* please break behind a space, if there is one. The space should
4307 if (sel_start_cursor.pos > 0
4308 && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1))
4309 sel_start_cursor.pos--;
4310 if (sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) {
4311 sel_start_cursor.par->Erase(sel_start_cursor.pos);
4314 sel_start_cursor.par->BreakParagraphConservative(sel_start_cursor.pos);
4315 tmppar = sel_start_cursor.par->Next();
4317 if (dummy_selection) {
4319 if (kind == LyXParagraph::TAB
4320 || kind == LyXParagraph::FIG
4321 || kind == LyXParagraph::WIDE_TAB
4322 || kind == LyXParagraph::WIDE_FIG
4323 || kind == LyXParagraph::ALGORITHM) {
4324 int lay = textclasslist.NumberOfLayout(parameters->textclass,
4326 if (lay == -1) // layout not found
4327 // use default layout "Standard" (0)
4329 tmppar->SetLayout(lay);
4333 if (sel_start_cursor.pos > 0) {
4334 /* the footnote-environment should begin with a standard layout.
4335 * Imagine you insert a footnote within an enumeration, you
4336 * certainly do not want an enumerated footnote! */
4340 /* this is a exception the user would sometimes expect, I hope */
4341 sel_start_cursor.par->Clear();
4345 while (tmppar != sel_end_cursor.par) {
4346 tmppar->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
4347 tmppar->footnotekind = kind;
4348 tmppar = tmppar->Next();
4351 RedoParagraphs(sel_start_cursor, sel_end_cursor.par->Next());
4353 SetCursor(sel_start_cursor.par->Next(), 0);
4359 // returns pointer to a specified row
4360 Row * LyXText::GetRow(LyXParagraph * par,
4361 LyXParagraph::size_type pos, long & y) const
4366 if (par == currentrow->par || par == currentrow->par->Previous()) {
4367 // do not dereference par, it may have been deleted
4368 // already! (Matthias)
4369 while (currentrow->previous && currentrow->previous->par != par) {
4370 currentrow = currentrow->previous;
4371 currentrow_y -= currentrow->height;
4373 while (currentrow->previous && currentrow->previous->par == par) {
4374 currentrow = currentrow->previous;
4375 currentrow_y -= currentrow->height;
4378 tmprow = currentrow;
4380 // find the first row of the specified paragraph
4381 while (tmprow->next && (tmprow->par != par)) {
4382 y += tmprow->height;
4383 tmprow = tmprow->next;
4386 if (tmprow->par == par){
4387 // now find the wanted row
4388 while (tmprow->pos < pos && tmprow->next && tmprow->next->par == par &&
4389 tmprow->next->pos <= pos) {
4390 y += tmprow->height;
4391 tmprow = tmprow->next;
4393 currentrow = tmprow;
4400 // find the first row of the specified paragraph
4401 while (tmprow->next && (tmprow->par != par)) {
4402 y += tmprow->height;
4403 tmprow = tmprow->next;
4406 // now find the wanted row
4407 while (tmprow->pos < pos && tmprow->next && tmprow->next->par == par &&
4408 tmprow->next->pos <= pos) {
4409 y += tmprow->height;
4410 tmprow = tmprow->next;
4413 currentrow = tmprow;