]> git.lyx.org Git - features.git/blobdiff - src/text2.C
clear()->erase() ; lots of using directives for cxx
[features.git] / src / text2.C
index ffbb5d2f8940cf6d6153cc183d8b56eea9854a5e..16ac40d0a53f0100b8de8bcfbe9bcfd09c278c98 100644 (file)
@@ -51,10 +51,7 @@ LyXText::LyXText(BufferView * bv, int pw, Buffer * p)
        owner_ = bv;
        firstrow = 0;
        lastrow = 0;
-       currentrow = 0;
-       currentrow_y = 0;
        paperwidth = pw;
-       //bparams = &p->params;
        buffer = p;
        number_of_rows = 0;
        refresh_y = 0;
@@ -87,6 +84,22 @@ LyXText::LyXText(BufferView * bv, int pw, Buffer * p)
 
        // Default layouttype for copy environment type
        copylayouttype = 0;
+
+#if 0
+       // Dump all rowinformation:
+       Row * tmprow = firstrow;
+       lyxerr << "Baseline Paragraph Pos Height Ascent Fill\n";
+       while (tmprow) {
+               lyxerr << tmprow->baseline << '\t'
+                      << tmprow->par << '\t'
+                      << tmprow->pos << '\t'
+                      << tmprow->height << '\t'
+                      << tmprow->ascent_of_text << '\t'
+                      << tmprow->fill << '\n';
+               tmprow = tmprow->next;
+       }
+       lyxerr.flush();
+#endif
 }
 
 
@@ -282,11 +295,6 @@ void LyXText::RemoveRow(Row * row) const
           row of this row */
        long unused_y;
        GetRow(row->par, row->pos, unused_y);
-       currentrow = currentrow->previous;
-       if (currentrow)
-               currentrow_y -= currentrow->height;
-       else
-               currentrow_y = 0;
    
        if (row->next)
                row->next->previous = row->previous;
@@ -466,12 +474,78 @@ void LyXText::MakeFontEntriesLayoutSpecific(LyXParagraph * par)
        }
 }
 
+LyXParagraph * LyXText::SetLayout(LyXCursor & cur, LyXCursor & sstart_cur,
+                                 LyXCursor & send_cur,
+                                 LyXTextClass::size_type layout)
+{
+       LyXParagraph * endpar = send_cur.par->LastPhysicalPar()->Next();
+       LyXParagraph * undoendpar = endpar;
+
+       if (endpar && endpar->GetDepth()) {
+               while (endpar && endpar->GetDepth()) {
+                       endpar = endpar->LastPhysicalPar()->Next();
+                       undoendpar = endpar;
+               }
+       } else if (endpar) {
+               endpar = endpar->Next(); // because of parindents etc.
+       }
+   
+       SetUndo(Undo::EDIT,
+               sstart_cur.par->ParFromPos(sstart_cur.pos)->previous, 
+               undoendpar);
+
+       /* ok we have a selection. This is always between sstart_cur
+        * and sel_end cursor */ 
+       cur = sstart_cur;
+   
+       LyXLayout const & lyxlayout =
+               textclasslist.Style(buffer->params.textclass, layout);
+   
+       while (cur.par != send_cur.par) {
+               if (cur.par->footnoteflag == sstart_cur.par->footnoteflag) {
+                       cur.par->SetLayout(layout);
+                       MakeFontEntriesLayoutSpecific(cur.par);
+                       LyXParagraph* fppar = cur.par->FirstPhysicalPar();
+                       fppar->added_space_top = lyxlayout.fill_top ?
+                               VSpace(VSpace::VFILL) : VSpace(VSpace::NONE);
+                       fppar->added_space_bottom = lyxlayout.fill_bottom ? 
+                               VSpace(VSpace::VFILL) : VSpace(VSpace::NONE); 
+                       if (lyxlayout.margintype == MARGIN_MANUAL)
+                               cur.par->SetLabelWidthString(lyxlayout.labelstring());
+                       if (lyxlayout.labeltype != LABEL_BIBLIO
+                           && fppar->bibkey) {
+                               delete fppar->bibkey;
+                               fppar->bibkey = 0;
+                       }
+               }
+               cur.par = cur.par->Next();
+       }
+       if (cur.par->footnoteflag == sstart_cur.par->footnoteflag) {
+               cur.par->SetLayout(layout);
+               MakeFontEntriesLayoutSpecific(cur.par);
+               LyXParagraph* fppar = cur.par->FirstPhysicalPar();
+               fppar->added_space_top = lyxlayout.fill_top ?
+                       VSpace(VSpace::VFILL) : VSpace(VSpace::NONE);
+               fppar->added_space_bottom = lyxlayout.fill_bottom ? 
+                       VSpace(VSpace::VFILL) : VSpace(VSpace::NONE); 
+               if (lyxlayout.margintype == MARGIN_MANUAL)
+                       cur.par->SetLabelWidthString(lyxlayout.labelstring());
+               if (lyxlayout.labeltype != LABEL_BIBLIO
+                   && fppar->bibkey) {
+                       delete fppar->bibkey;
+                       fppar->bibkey = 0;
+               }
+       }
+       return endpar;
+}
 
 // set layout over selection and make a total rebreak of those paragraphs
 void LyXText::SetLayout(LyXTextClass::size_type layout)
 {
-       LyXCursor tmpcursor;
+       LyXCursor
+               tmpcursor = cursor;  /* store the current cursor  */
 
+#ifdef USE_OLD_SET_LAYOUT
        // if there is no selection just set the layout
        // of the current paragraph  */
        if (!selection) {
@@ -496,8 +570,6 @@ void LyXText::SetLayout(LyXTextClass::size_type layout)
                sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous, 
                undoendpar);
 
-       tmpcursor = cursor;                    /* store the current cursor  */
-
        /* ok we have a selection. This is always between sel_start_cursor
         * and sel_end cursor */ 
        cursor = sel_start_cursor;
@@ -542,7 +614,16 @@ void LyXText::SetLayout(LyXTextClass::size_type layout)
                        fppar->bibkey = 0;
                }
        }
-   
+#else
+       // if there is no selection just set the layout
+       // of the current paragraph  */
+       if (!selection) {
+               sel_start_cursor = cursor;  // dummy selection
+               sel_end_cursor = cursor;
+       }
+       LyXParagraph *
+       endpar = SetLayout(cursor, sel_start_cursor, sel_end_cursor, layout);
+#endif
        RedoParagraphs(sel_start_cursor, endpar);
    
        // we have to reset the selection, because the
@@ -910,14 +991,14 @@ void LyXText::RedoParagraphs(LyXCursor const & cur,
 }
 
 
-int LyXText::FullRebreak()
+bool LyXText::FullRebreak()
 {
        if (need_break_row) {
                BreakAgain(need_break_row);
                need_break_row = 0;
-               return 1;
+               return true;
        }
-       return 0;
+       return false;
 }
 
 
@@ -1041,38 +1122,21 @@ void  LyXText::CursorBottom() const
    
 /* returns a pointer to the row near the specified y-coordinate
 * (relative to the whole text). y is set to the real beginning
-* of this row */ 
+* of this row */
 Row * LyXText::GetRowNearY(long & y) const
 {
-       Row * tmprow;
-       long tmpy;
-   
-       if (currentrow) {
-               tmprow = currentrow;
-               tmpy = currentrow_y;
-       } else {
-               tmprow = firstrow;
-               tmpy = 0;
-       }
-
-       if (tmpy <= y)
-               while (tmprow->next && tmpy + tmprow->height <= y) {
-                       tmpy += tmprow->height;
-                       tmprow = tmprow->next;
-               }
-       else
-               while (tmprow->previous && tmpy > y) {
-                       tmprow = tmprow->previous;
-                       tmpy -= tmprow->height;
-               }
+       Row * tmprow = firstrow;
+       long tmpy = 0;
 
-       currentrow = tmprow;
-       currentrow_y = tmpy;
+       while (tmprow->next && tmpy + tmprow->height <= y) {
+               tmpy += tmprow->height;
+               tmprow = tmprow->next;
+       }
 
        y = tmpy;   // return the real y
        return tmprow;
 }
-   
+
 
 void LyXText::ToggleFree(LyXFont const & font, bool toggleall)
 {
@@ -1511,7 +1575,7 @@ void LyXText::SetCounter(LyXParagraph * par) const
        }
    
        if (!par->labelstring.empty()) {
-               par->labelstring.clear();
+               par->labelstring.erase();
        }
    
        if (layout.margintype == MARGIN_MANUAL) {
@@ -1534,12 +1598,12 @@ void LyXText::SetCounter(LyXParagraph * par) const
                                if (!layout.labelstring().empty())
                                        par->labelstring = layout.labelstring();
                                else
-                                       par->labelstring.clear();
+                                       par->labelstring.erase();
                         } else {
                                if (!layout.labelstring_appendix().empty())
                                        par->labelstring = layout.labelstring_appendix();
                                else
-                                       par->labelstring.clear();
+                                       par->labelstring.erase();
                        }
 
 #ifdef HAVE_SSTREAM
@@ -2219,7 +2283,7 @@ void LyXText::CopySelection()
        DeleteSimpleCutBuffer();
 
        // set the textclass
-       simple_cut_buffer_textclass = buffer->params->textclass;
+       simple_cut_buffer_textclass = buffer->params.textclass;
 
        // copy behind a space if there is one
        while (sel_start_cursor.par->Last() > sel_start_cursor.pos
@@ -2466,7 +2530,7 @@ void LyXText::PasteSelection()
      
                // make sure there is no class difference
                cap.SwitchLayoutsBetweenClasses(simple_cut_buffer_textclass,
-                                               buffer->params->textclass,
+                                               buffer->params.textclass,
                                                simple_cut_buffer);
      
                // make the simple_cut_buffer exactly the same layout than
@@ -2897,8 +2961,8 @@ bool LyXText::GotoNextNote() const
 void LyXText::CheckParagraph(LyXParagraph * par,
                             LyXParagraph::size_type pos)
 {
-  
-       LyXCursor tmpcursor;
+       LyXCursor tmpcursor;                    
+
 
        /* table stuff -- begin*/
    
@@ -3699,17 +3763,8 @@ bool LyXText::TextHandleUndo(Undo * undo)
                                if (undo->kind == Undo::EDIT) {
                                        tmppar2->setContentsFromPar(tmppar);
                                        tmppar->clearContents();
-                                       //tmppar2->text = tmppar->text;
-                                       //tmppar->text.clear();
                                        tmppar2 = tmppar2->next;
                                }
-                               if ( currentrow && currentrow->par == tmppar )
-                                       currentrow = currentrow -> previous;
-                               // Commenting out this might remove the error
-                               // reported by Purify, but it might also
-                               // introduce a memory leak. We need to
-                               // check this (Lgb)
-                               //delete tmppar;
                        }
                }