]> git.lyx.org Git - lyx.git/blobdiff - src/Cursor.cpp
* do not lookup the same macro all the time
[lyx.git] / src / Cursor.cpp
index 134017e865824d37f5d37de655ab3580a9a89743..95d44b747b95473dbaf14ccbea266976dcdc348e 100644 (file)
 #include "FuncRequest.h"
 #include "Language.h"
 #include "lfuns.h"
-#include "LyXFont.h"
+#include "Font.h"
 #include "LyXFunc.h" // only for setMessage()
 #include "LyXRC.h"
 #include "Row.h"
-#include "LyXText.h"
+#include "Text.h"
 #include "Paragraph.h"
 #include "paragraph_funcs.h"
 #include "ParIterator.h"
@@ -93,10 +93,10 @@ namespace {
                for (size_t i = 0;; ++i) {
                        int xo;
                        int yo;
-                       InsetBase const * inset = &it.inset();
-                       std::map<InsetBase const *, Point> const & data =
+                       Inset const * inset = &it.inset();
+                       std::map<Inset const *, Point> const & data =
                                c.bv().coordCache().getInsets().getData();
-                       std::map<InsetBase const *, Point>::const_iterator I = data.find(inset);
+                       std::map<Inset const *, Point>::const_iterator I = data.find(inset);
 
                        // FIXME: in the case where the inset is not in the cache, this
                        // means that no part of it is visible on screen. In this case
@@ -134,7 +134,7 @@ namespace {
                int x, int y, int xlow, int xhigh, int ylow, int yhigh)
        {
                BOOST_ASSERT(!cursor.empty());
-               InsetBase & inset = cursor[0].inset();
+               Inset & inset = cursor[0].inset();
                BufferView & bv = cursor.bv();
 
                CoordCache::InnerParPosCache const & cache =
@@ -203,7 +203,7 @@ namespace {
                //      << " xlow: " << xlow << " xhigh: " << xhigh
                //      << " ylow: " << ylow << " yhigh: " << yhigh
                //      << endl;
-               InsetBase & inset = bv.buffer()->inset();
+               Inset & inset = bv.buffer()->inset();
                DocIterator it = doc_iterator_begin(inset);
                it.pit() = from;
                DocIterator et = doc_iterator_end(inset);
@@ -245,6 +245,17 @@ namespace {
                return true;
        }
 
+       docstring parbreak(Paragraph const & par)
+       {
+               odocstringstream ods;
+               ods << '\n';
+               // only add blank line if we're not in an ERT or Listings inset
+               if (par.ownerCode() != Inset::ERT_CODE 
+                   && par.ownerCode() != Inset::LISTINGS_CODE)
+                       ods << '\n';
+               return ods.str();
+       }
+
 } // namespace anon
 
 
@@ -256,7 +267,7 @@ Cursor::Cursor(BufferView & bv)
 {}
 
 
-void Cursor::reset(InsetBase & inset)
+void Cursor::reset(Inset & inset)
 {
        clear();
        push_back(CursorSlice(inset));
@@ -341,13 +352,13 @@ void Cursor::pop()
 }
 
 
-void Cursor::push(InsetBase & p)
+void Cursor::push(Inset & p)
 {
        push_back(CursorSlice(p));
 }
 
 
-void Cursor::pushLeft(InsetBase & p)
+void Cursor::pushLeft(Inset & p)
 {
        BOOST_ASSERT(!empty());
        //lyxerr << "Entering inset " << t << " left" << endl;
@@ -387,10 +398,10 @@ int Cursor::currentMode()
        BOOST_ASSERT(!empty());
        for (int i = depth() - 1; i >= 0; --i) {
                int res = operator[](i).inset().currentMode();
-               if (res != InsetBase::UNDECIDED_MODE)
+               if (res != Inset::UNDECIDED_MODE)
                        return res;
        }
-       return InsetBase::TEXT_MODE;
+       return Inset::TEXT_MODE;
 }
 
 
@@ -541,7 +552,7 @@ void Cursor::info(odocstream & os) const
                os << "  ";
        }
        if (pos() != 0) {
-               InsetBase const * inset = prevInset();
+               Inset const * inset = prevInset();
                // prevInset() can return 0 in certain case.
                if (inset)
                        prevInset()->infoize2(os);
@@ -608,7 +619,7 @@ namespace lyx {
 //#define FILEDEBUG 1
 
 
-bool Cursor::isInside(InsetBase const * p)
+bool Cursor::isInside(Inset const * p)
 {
        for (size_t i = 0; i != depth(); ++i)
                if (&operator[](i).inset() == p)
@@ -617,7 +628,7 @@ bool Cursor::isInside(InsetBase const * p)
 }
 
 
-void Cursor::leaveInset(InsetBase const & inset)
+void Cursor::leaveInset(Inset const & inset)
 {
        for (size_t i = 0; i != depth(); ++i) {
                if (&operator[](i).inset() == &inset) {
@@ -712,7 +723,7 @@ void Cursor::insert(MathAtom const & t)
 }
 
 
-void Cursor::insert(InsetBase * inset)
+void Cursor::insert(Inset * inset)
 {
        if (inMathed())
                insert(MathAtom(inset));
@@ -1178,12 +1189,14 @@ docstring Cursor::selectionAsString(bool label) const
 
                // First paragraph in selection
                docstring result = pars[startpit].
-                       asString(buffer, startpos, pars[startpit].size(), label) + "\n\n";
+                       asString(buffer, startpos, pars[startpit].size(), label)
+                                + parbreak(pars[startpit]);
 
                // The paragraphs in between (if any)
                for (pit_type pit = startpit + 1; pit != endpit; ++pit) {
                        Paragraph const & par = pars[pit];
-                       result += par.asString(buffer, 0, par.size(), label) + "\n\n";
+                       result += par.asString(buffer, 0, par.size(), label)
+                                 + parbreak(pars[pit]);
                }
 
                // Last paragraph in selection
@@ -1233,8 +1246,8 @@ Encoding const * Cursor::getEncoding() const
                if (operator[](s).text())
                        break;
        CursorSlice const & sl = operator[](s);
-       LyXText const & text = *sl.text();
-       LyXFont font = text.getPar(sl.pit()).getFont(
+       Text const & text = *sl.text();
+       Font font = text.getPar(sl.pit()).getFont(
                bv().buffer()->params(), sl.pos(), outerFont(sl.pit(), text.paragraphs()));
        return font.language()->encoding();
 }
@@ -1264,7 +1277,7 @@ void Cursor::noUpdate()
 }
 
 
-LyXFont Cursor::getFont() const
+Font Cursor::getFont() const
 {
        // HACK. far from being perfect...
        int s = 0;
@@ -1274,8 +1287,8 @@ LyXFont Cursor::getFont() const
                if (operator[](s).text())
                        break;
        CursorSlice const & sl = operator[](s);
-       LyXText const & text = *sl.text();
-       LyXFont font = text.getPar(sl.pit()).getFont(
+       Text const & text = *sl.text();
+       Font font = text.getPar(sl.pit()).getFont(
                bv().buffer()->params(),
                sl.pos(),
                outerFont(sl.pit(), text.paragraphs()));