]> git.lyx.org Git - lyx.git/blobdiff - src/cursor.C
Fix my breakage. Sorry guys.
[lyx.git] / src / cursor.C
index 9b986ab506476195f1e1f7ac582e0c30c5fee0d1..b78d054fc406f2a422f45d731aa27b8054b1ccc3 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());
@@ -304,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);
@@ -1132,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 & 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;
+}