]> git.lyx.org Git - lyx.git/blobdiff - src/CutAndPaste.C
get rid of LYX_LIBS
[lyx.git] / src / CutAndPaste.C
index ffae84eb459862a8d4df6649f28eb1b784b9fd09..0ad7fe6162367b521f4a37fea0b7653fd07f329c 100644 (file)
@@ -9,22 +9,23 @@
 
 #include <config.h>
 
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
 #include "CutAndPaste.h"
 #include "BufferView.h"
 #include "buffer.h"
 #include "paragraph.h"
-#include "insets/inseterror.h"
-#include "lyx_gui_misc.h"
 #include "lyxcursor.h"
 #include "gettext.h"
+#include "iterators.h"
+#include "lyxtextclasslist.h"
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
+#include "insets/inseterror.h"
 
 using std::pair;
 using lyx::pos_type;
-using lyx::layout_type;
 using lyx::textclass_type;
 
 extern BufferView * current_view;
@@ -141,7 +142,7 @@ bool CutAndPaste::cutSelection(Paragraph * startpar, Paragraph ** endpar,
                }
                // this paragraph's are of noone's owner!
                Paragraph * p = buf;
-               while(p) {
+               while (p) {
                        p->setInsetOwner(0);
                        p = p->next();
                }
@@ -198,7 +199,7 @@ bool CutAndPaste::copySelection(Paragraph * startpar, Paragraph * endpar,
                }
                // this paragraph's are of noone's owner!
                tmppar = buf;
-               while(tmppar) {
+               while (tmppar) {
                        tmppar->setInsetOwner(0);
                        tmppar = tmppar->next();
                }
@@ -216,10 +217,11 @@ bool CutAndPaste::pasteSelection(Paragraph ** par, Paragraph ** endpar,
        if (pos > (*par)->size())
                pos = (*par)->size();
        
+#if 0
        // Paragraph * tmpbuf;
        Paragraph * tmppar = *par;
        int tmppos = pos;
-       
+
        // There are two cases: cutbuffer only one paragraph or many
        if (!buf->next()) {
                // only within a paragraph
@@ -248,7 +250,9 @@ bool CutAndPaste::pasteSelection(Paragraph ** par, Paragraph ** endpar,
                buf = tmpbuf;
                *endpar = tmppar->next();
                pos = tmppos;
-       } else {
+       } else
+#endif
+       {
                // many paragraphs
                
                // make a copy of the simple cut_buffer
@@ -262,9 +266,35 @@ bool CutAndPaste::pasteSelection(Paragraph ** par, Paragraph ** endpar,
                        tmpbuf2->next()->previous(tmpbuf2);
                        tmpbuf2 = tmpbuf2->next();
                }
+
+               // now remove all out of the buffer which is NOT allowed in the
+               // new environment and set also another font if that is required
+               tmpbuf = buf;
+               while(tmpbuf) {
+                       // set the inset owner of this paragraph
+                       tmpbuf->setInsetOwner((*par)->inInset());
+                       for(pos_type i = 0; i < tmpbuf->size(); ++i) {
+                               if (tmpbuf->getChar(i) == Paragraph::META_INSET) {
+                                       if (!(*par)->insetAllowed(tmpbuf->getInset(i)->lyxCode()))
+                                       {
+                                               tmpbuf->erase(i--);
+                                       }
+                               } else {
+                                       LyXFont f1 = tmpbuf->getFont(current_view->buffer()->params,i);
+                                       LyXFont f2 = f1;
+                                       if (!(*par)->checkInsertChar(f1)) {
+                                               tmpbuf->erase(i--);
+                                       } else if (f1 != f2) {
+                                               tmpbuf->setFont(i, f1);
+                                       }
+                               }
+                       }
+                       tmpbuf = tmpbuf->next();
+               }
                
                // make sure there is no class difference
-               SwitchLayoutsBetweenClasses(textclass, tc, buf);
+               SwitchLayoutsBetweenClasses(textclass, tc, buf,
+                                           current_view->buffer()->params);
                
                // make the buf exactly the same layout than
                // the cursor paragraph
@@ -329,7 +359,7 @@ int CutAndPaste::nrOfParagraphs()
        
        int n = 1;
        Paragraph * tmppar = buf;
-       while(tmppar->next()) {
+       while (tmppar->next()) {
                ++n;
                tmppar = tmppar->next();
        }
@@ -338,37 +368,44 @@ int CutAndPaste::nrOfParagraphs()
 
 
 int CutAndPaste::SwitchLayoutsBetweenClasses(textclass_type c1,
-                                            textclass_type c2, Paragraph * par)
+                                            textclass_type c2,
+                                            Paragraph * par,
+                                            BufferParams const & bparams)
 {
        int ret = 0;
        if (!par || c1 == c2)
                return ret;
-       
-       while (par) {
-               string const name = textclasslist.NameOfLayout(c1, par->layout);
-               int lay = 0;
-               pair<bool, layout_type> pp =
-                       textclasslist.NumberOfLayout(c2, name);
-               if (pp.first) {
-                       lay = pp.second;
-               } else { // layout not found
-                       // use default layout "Standard" (0)
-                       lay = 0;
+
+       ParIterator end = ParIterator();
+       for (ParIterator it = ParIterator(par); it != end; ++it) {
+               par = *it;
+               string const name = par->layout();
+               LyXTextClass const & tclass = textclasslist[c2];
+               
+               bool hasLayout = tclass.hasLayout(name);
+               
+               string lay = tclass.defaultLayoutName();
+               if (hasLayout) {
+                       lay = name;
+               } else {
+                       // not found: use default layout
+                       lay = tclass.defaultLayoutName();
                }
-               par->layout = lay;
+               par->layout(lay);
                
-               if (name != textclasslist.NameOfLayout(c2, par->layout)) {
+               if (name != par->layout()) {
                        ++ret;
                        string const s = _("Layout had to be changed from\n")
                                + name + _(" to ")
-                               + textclasslist.NameOfLayout(c2, par->layout)
+                               + par->layout()
                                + _("\nbecause of class conversion from\n")
-                               + textclasslist.NameOfClass(c1) + _(" to ")
-                               + textclasslist.NameOfClass(c2);
+                               + textclasslist[c1].name() + _(" to ")
+                               + textclasslist[c2].name();
                        InsetError * new_inset = new InsetError(s);
-                       par->insertInset(0, new_inset);
+                       par->insertInset(0, new_inset,
+                                        LyXFont(LyXFont::ALL_INHERIT,
+                                                bparams.language));
                }
-               par = par->next();
        }
        return ret;
 }