]> git.lyx.org Git - lyx.git/blobdiff - src/cursor.C
ws changes mostly
[lyx.git] / src / cursor.C
index 0be9a3263237c7cd15038ba500432653a3c429d5..e0b4e20453f9149743c793c8b5ca74dd3b8f81bc 100644 (file)
@@ -50,6 +50,7 @@
 #include <boost/current_function.hpp>
 
 #include <sstream>
+#include <limits>
 
 using lyx::pit_type;
 
@@ -160,7 +161,6 @@ namespace {
                return false;
        }
 
-
 } // namespace anon
 
 
@@ -192,7 +192,8 @@ void LCursor::setCursor(DocIterator const & cur)
 
 void LCursor::dispatch(FuncRequest const & cmd0)
 {
-       lyxerr[Debug::DEBUG] << "LCursor::dispatch: cmd: " << cmd0 << endl << *this << endl;
+       lyxerr[Debug::DEBUG] << "LCursor::dispatch: cmd: "
+               << cmd0 << endl << *this << endl;
        if (empty())
                return;
 
@@ -200,7 +201,8 @@ void LCursor::dispatch(FuncRequest const & cmd0)
        LCursor safe = *this;
 
        for (; size(); pop()) {
-               lyxerr[Debug::DEBUG] << "LCursor::dispatch: cmd: " << cmd0 << endl << *this << endl;
+               lyxerr[Debug::DEBUG] << "LCursor::dispatch: cmd: "
+                       << cmd0 << endl << *this << endl;
                BOOST_ASSERT(pos() <= lastpos());
                BOOST_ASSERT(idx() <= lastidx());
                BOOST_ASSERT(pit() <= lastpit());
@@ -230,45 +232,6 @@ DispatchResult LCursor::result() const
 }
 
 
-bool LCursor::getStatus(FuncRequest const & cmd, FuncStatus & status)
-{
-       // This is, of course, a mess. Better create a new doc iterator and use
-       // this in Inset::getStatus. This might require an additional
-       // BufferView * arg, though (which should be avoided)
-       LCursor safe = *this;
-       bool res = false;
-       for ( ; size(); pop()) {
-               //lyxerr << "\nLCursor::getStatus: cmd: " << cmd << endl << *this << endl;
-               if (idx() > lastidx()) {
-                       lyxerr << "wrong idx " << idx() << ", max is " << lastidx()
-                               << ". Trying to correct this."  << endl;
-                       idx() = lastidx();
-               }
-               if (pit() > lastpit()) {
-                       lyxerr << "wrong par " << pit() << ", max is " << lastpit()
-                               << ". Trying to correct this."  << endl;
-                       pit() = lastpit();
-               }
-               if (pos() > lastpos()) {
-                       lyxerr << "wrong pos " << pos() << ", max is " << lastpos()
-                               << ". Trying to correct this."  << endl;
-                       pos() = lastpos();
-               }
-
-               // The inset's getStatus() will return 'true' if it made
-               // a definitive decision on whether it want to handle the
-               // request or not. The result of this decision is put into
-               // the 'status' parameter.
-               if (inset().getStatus(*this, cmd, status)) {
-                       res = true;
-                       break;
-               }
-       }
-       operator=(safe);
-       return res;
-}
-
-
 BufferView & LCursor::bv() const
 {
        BOOST_ASSERT(bv_);
@@ -343,25 +306,6 @@ int LCursor::currentMode()
 }
 
 
-void LCursor::getDim(int & asc, int & des) const
-{
-       if (inMathed()) {
-               BOOST_ASSERT(inset().asMathInset());
-               //inset().asMathInset()->getCursorDim(asc, des);
-               asc = 10;
-               des = 2;
-       } else if (inTexted()) {
-               LyXFont const & realfont = text()->real_current_font;
-               asc = font_metrics::maxAscent(realfont);
-               des = font_metrics::maxDescent(realfont);
-       } else {
-               lyxerr << "should this happen?" << endl;
-               asc = 10;
-               des = 10;
-       }
-}
-
-
 void LCursor::getPos(int & x, int & y) const
 {
        Point p = bv_funcs::getPos(*this);
@@ -1142,7 +1086,7 @@ Encoding const * LCursor::getEncoding() const
                if (operator[](s).text())
                        break;
        CursorSlice const & sl = operator[](s);
-       LyXText & text = *sl.text();
+       LyXText const & text = *sl.text();
        LyXFont font = text.getPar(sl.pit()).getFont(
                bv().buffer()->params(), sl.pos(), outerFont(sl.pit(), text.paragraphs()));
        return font.language()->encoding();
@@ -1171,3 +1115,24 @@ void LCursor::noUpdate()
 {
        disp_.update(false);
 }
+
+
+LyXFont LCursor::getFont() const
+{
+       // HACK. far from being perfect...
+       int s = 0;
+       // go up until first non-0 text is hit
+       // (innermost text is 0 in mathed)
+       for (s = size() - 1; s >= 0; --s)
+               if (operator[](s).text())
+                       break;
+       CursorSlice const & sl = operator[](s);
+       LyXText const & text = *sl.text();
+       LyXFont font = text.getPar(sl.pit()).getFont(
+               bv().buffer()->params(),
+               sl.pos(),
+               outerFont(sl.pit(), text.paragraphs()));
+       for (; s < size(); ++s)
+               ;
+       return font;
+}