]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
Fixed cut&paste bugs and added freespacing for ERT Insets.
[lyx.git] / src / text.C
index a7f2cbd330e1cef94814accdc594c751365fa438..8e5d3ea8d41b499d9aa5ee4cda39c7b44b7810fd 100644 (file)
@@ -46,6 +46,7 @@ using std::max;
 using std::min;
 using std::endl;
 using std::pair;
+using lyx::pos_type;
 
 namespace {
 
@@ -230,7 +231,7 @@ int LyXText::singleWidth(BufferView * bview, Paragraph * par,
 
 
 // Returns the paragraph position of the last character in the specified row
-LyXText::pos_type LyXText::rowLast(Row const * row) const
+pos_type LyXText::rowLast(Row const * row) const
 {
        if (row->next() == 0)
                return row->par()->size() - 1;
@@ -241,7 +242,7 @@ LyXText::pos_type LyXText::rowLast(Row const * row) const
 }
 
 
-LyXText::pos_type LyXText::rowLastPrintable(Row const * row) const
+pos_type LyXText::rowLastPrintable(Row const * row) const
 {
        pos_type const last = rowLast(row);
        if (last >= row->pos()
@@ -878,7 +879,7 @@ int LyXText::labelEnd(BufferView * bview, Row const * row) const
 
 
 // get the next breakpoint in a given paragraph
-LyXText::pos_type
+pos_type
 LyXText::nextBreakPoint(BufferView * bview, Row const * row, int width) const
 {
        Paragraph * par = row->par();
@@ -888,7 +889,6 @@ LyXText::nextBreakPoint(BufferView * bview, Row const * row, int width) const
 
        pos_type const pos = row->pos();
 
-
        // position of the last possible breakpoint 
        // -1 isn't a suitable value, but a flag
        pos_type last_separator = -1;
@@ -1746,7 +1746,8 @@ void LyXText::insertChar(BufferView * bview, char c)
 
        bool const freeSpacing = 
                textclasslist.Style(bview->buffer()->params.textclass,
-                              cursor.row()->par()->getLayout()).free_spacing;
+                              cursor.row()->par()->getLayout()).free_spacing ||
+               cursor.row()->par()->isFreeSpacing();
 
 
        if (lyxrc.auto_number) {
@@ -3154,7 +3155,8 @@ void LyXText::paintFirstRow(DrawRowParams & p)
        // draw a top pagebreak
        if (parparams.pagebreakTop()) {
                int const y = p.yo + y_top + 2*defaultHeight();
-               p.pain->line(0, y, p.width, y, LColor::pagebreak, Painter::line_onoffdash);
+               p.pain->line(p.xo, y, p.xo + p.width, y, 
+                       LColor::pagebreak, Painter::line_onoffdash);
  
                int w = 0;
                int a = 0;
@@ -3175,18 +3177,43 @@ void LyXText::paintFirstRow(DrawRowParams & p)
                int const y1 = p.yo + y_top + 3 * defaultHeight();
                int const y2 = p.yo + 2 + y_top;
  
-               p.pain->line(0, y1, LYX_PAPER_MARGIN, y1, LColor::vfillline);
+               p.pain->line(0, y1, LYX_PAPER_MARGIN, y1, LColor::added_space);
                
-               p.pain->line(0, y2, LYX_PAPER_MARGIN, y2, LColor::vfillline);
+               p.pain->line(0, y2, LYX_PAPER_MARGIN, y2, LColor::added_space);
 
                int const x = LYX_PAPER_MARGIN / 2;
  
-               p.pain->line(x, y2, x, y1, LColor::vfillline);
+               p.pain->line(x, y2, x, y1, LColor::added_space);
                
                y_top += 3 * defaultHeight();
+       } else if (parparams.spaceTop().kind() == VSpace::LENGTH) {
+               string str = string(_("Space above")) + " ("
+                       + parparams.spaceTop().asLyXCommand()
+                       + ")";
+               int const space = int(parparams.spaceTop().inPixels(p.bv));
+               int const y = p.yo + y_top + space / 2;
+               p.pain->line(p.xo, y, p.xo + p.width, y, 
+                       LColor::added_space, Painter::line_onoffdash);
+               int w = 0;
+               int a = 0;
+               int d = 0;
+               LyXFont pb_font;
+               pb_font.setColor(LColor::added_space).decSize();
+               lyxfont::rectText(str, pb_font, w, a, d);
+
+               // don't draw if it won't fit 
+               if (a + d + 4 < space) { 
+                       p.pain->rectText(p.xo + (p.width - w)/2, y + d,
+                                     str, pb_font,
+                                     backgroundColor(),
+                                     backgroundColor());
+               }
        }
        
-       // think about user added space
        y_top += int(parparams.spaceTop().inPixels(p.bv));
        
        Buffer const * buffer = p.bv->buffer();
@@ -3350,7 +3377,7 @@ void LyXText::paintLastRow(DrawRowParams & p)
                pb_font.setColor(LColor::pagebreak).decSize();
                int const y = p.yo + y_bottom - 2 * defaultHeight();
  
-               p.pain->line(0, y, ww, y, LColor::pagebreak, Painter::line_onoffdash);
+               p.pain->line(p.xo, y, p.xo + p.width, y, LColor::pagebreak, Painter::line_onoffdash);
  
                int w = 0;
                int a = 0;
@@ -3370,11 +3397,38 @@ void LyXText::paintLastRow(DrawRowParams & p)
                int const y = p.yo + y_bottom - 3 * defaultHeight();
                int const y2 = p.yo + y_bottom - 2;
                
-               p.pain->line(0, y, x2, y, LColor::vfillline);
-               p.pain->line(0, y2, x2, y2, LColor::vfillline);
-               p.pain->line(x, y, x, y2, LColor::vfillline);
+               p.pain->line(0, y, x2, y, LColor::added_space);
+               p.pain->line(0, y2, x2, y2, LColor::added_space);
+               p.pain->line(x, y, x, y2, LColor::added_space);
  
                y_bottom -= 3 * defaultHeight();
+       } else if (parparams.spaceBottom().kind() == VSpace::LENGTH) {
+               string str = string(_("Space below"))
+                       + " ("
+                       + parparams.spaceBottom().asLyXCommand()
+                       + ")";
+               int const space = int(parparams.spaceBottom().inPixels(p.bv));
+               int const y = p.yo + y_bottom - space / 2;
+               p.pain->line(p.xo, y, p.xo + p.width, y,
+                       LColor::added_space, Painter::line_onoffdash);
+               int w = 0;
+               int a = 0;
+               int d = 0;
+               LyXFont pb_font;
+               pb_font.setColor(LColor::added_space).decSize();
+               lyxfont::rectText(str, pb_font, w, a, d);
+
+               // don't draw if it won't fit 
+               if (a + d + 4 < space) { 
+                       p.pain->rectText(p.xo + (p.width - w) / 2, y + d,
+                                     str, pb_font,
+                                     backgroundColor(),
+                                     backgroundColor());
+               } 
        }
        
        // think about user added space
@@ -3480,7 +3534,7 @@ void LyXText::paintRowText(DrawRowParams & p)
                        int const y1 = y0 - defaultHeight() / 2;
 
                        p.pain->line(int(p.x), y1, int(p.x), y0,
-                                    LColor::vfillline);
+                                    LColor::added_space);
                        
                        if (hfillExpansion(buffer, p.row, pos)) {
                                int const y2 = (y0 + y1) / 2;
@@ -3488,19 +3542,19 @@ void LyXText::paintRowText(DrawRowParams & p)
                                if (pos >= main_body) {
                                        p.pain->line(int(p.x), y2,
                                                  int(p.x + p.hfill), y2,
-                                                 LColor::vfillline,
+                                                 LColor::added_space,
                                                  Painter::line_onoffdash);
                                        p.x += p.hfill;
                                } else {
                                        p.pain->line(int(p.x), y2,
                                                  int(p.x + p.label_hfill), y2,
-                                                 LColor::vfillline,
+                                                 LColor::added_space,
                                                  Painter::line_onoffdash);
                                        p.x += p.label_hfill;
                                }
                                p.pain->line(int(p.x), y1,
                                             int(p.x), y0,
-                                            LColor::vfillline);
+                                            LColor::added_space);
                        }
                        p.x += 2;
                        ++vpos;
@@ -3570,7 +3624,7 @@ void LyXText::getVisibleRow(BufferView * bv, int y_offset, int x_offset,
        // paint text
        paintRowText(p); 
 }
-
 
 int LyXText::defaultHeight() const
 {
@@ -3581,7 +3635,7 @@ int LyXText::defaultHeight() const
    
 /* returns the column near the specified x-coordinate of the row 
 * x is set to the real beginning of this column  */ 
-LyXText::pos_type
+pos_type
 LyXText::getColumnNearX(BufferView * bview, Row * row, int & x,
                        bool & boundary) const
 {