]> git.lyx.org Git - lyx.git/blobdiff - src/Cursor.cpp
adjust
[lyx.git] / src / Cursor.cpp
index 111434b6c89bbf17559f9c54e65a820ff00803c8..4e4770a4ca9aa32deeb814aef61a0dfcce37c5a8 100644 (file)
@@ -15,7 +15,6 @@
 
 #include "Bidi.h"
 #include "BufferView.h"
-#include "bufferview_funcs.h"
 #include "Buffer.h"
 #include "Cursor.h"
 #include "CoordCache.h"
@@ -34,6 +33,7 @@
 #include "Paragraph.h"
 #include "paragraph_funcs.h"
 #include "ParIterator.h"
+#include "TextMetrics.h"
 
 #include "insets/InsetTabular.h"
 #include "insets/InsetText.h"
@@ -97,9 +97,9 @@ namespace {
                        int xo;
                        int yo;
                        Inset const * inset = &it.inset();
-                       std::map<Inset const *, Point> const & data =
+                       std::map<Inset const *, Geometry> const & data =
                                c.bv().coordCache().getInsets().getData();
-                       std::map<Inset const *, Point>::const_iterator I = data.find(inset);
+                       std::map<Inset const *, Geometry>::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
@@ -110,7 +110,7 @@ namespace {
                                return it;
                        }
 
-                       Point o = I->second;
+                       Point o = I->second.pos;
                        inset->cursorPos(c.bv(), it.top(), c.boundary(), xo, yo);
                        // Convert to absolute
                        xo += o.x_;
@@ -132,6 +132,7 @@ namespace {
        }
 
 
+       /*
        /// moves position closest to (x, y) in given box
        bool bruteFind(Cursor & cursor,
                int x, int y, int xlow, int xhigh, int ylow, int yhigh)
@@ -161,7 +162,7 @@ namespace {
                for ( ; it != et; it.forwardPos(true)) {
                        // avoid invalid nesting when selecting
                        if (!cursor.selection() || positionable(it, cursor.anchor_)) {
-                               Point p = bv_funcs::getPos(bv, it, false);
+                               Point p = bv.getPos(it, false);
                                int xo = p.x_;
                                int yo = p.y_;
                                if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
@@ -186,6 +187,7 @@ namespace {
 
                return false;
        }
+       */
 
 
        /// moves position closest to (x, y) in given box
@@ -216,9 +218,9 @@ namespace {
 
                for ( ; it != et; it.forwardPos()) {
                        // avoid invalid nesting when selecting
-                       if (bv_funcs::status(&bv, it) == bv_funcs::CUR_INSIDE
+                       if (bv.cursorStatus(it) == CUR_INSIDE
                            && (!cur.selection() || positionable(it, cur.anchor_))) {
-                               Point p = bv_funcs::getPos(bv, it, false);
+                               Point p = bv.getPos(it, false);
                                int xo = p.x_;
                                int yo = p.y_;
                                if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
@@ -253,8 +255,8 @@ namespace {
                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)
+               if (par.ownerCode() != ERT_CODE
+                   && par.ownerCode() != LISTINGS_CODE)
                        ods << '\n';
                return ods.str();
        }
@@ -266,7 +268,7 @@ namespace {
 // bv functions are not yet available!
 Cursor::Cursor(BufferView & bv)
        : DocIterator(), bv_(&bv), anchor_(), x_target_(-1), textTargetOffset_(0),
-         selection_(false), mark_(false), logicalpos_(false)
+         selection_(false), mark_(false), logicalpos_(false), current_font(Font::ALL_INHERIT)
 {}
 
 
@@ -417,7 +419,7 @@ int Cursor::currentMode()
 
 void Cursor::getPos(int & x, int & y) const
 {
-       Point p = bv_funcs::getPos(bv(), *this, boundary());
+       Point p = bv().getPos(*this, boundary());
        x = p.x_;
        y = p.y_;
 }
@@ -680,10 +682,10 @@ bool Cursor::openable(MathAtom const & t) const
 }
 
 
-void Cursor::setScreenPos(int x, int y)
+void Cursor::setScreenPos(int x, int /*y*/)
 {
        setTargetX(x);
-       bruteFind(*this, x, y, 0, bv().workWidth(), 0, bv().workHeight());
+       //bruteFind(*this, x, y, 0, bv().workWidth(), 0, bv().workHeight());
 }
 
 
@@ -1213,7 +1215,7 @@ bool Cursor::upDownInText(bool up, bool & updateNeeded)
                xo = targetX();
                
        // first get the current line
-       TextMetrics const & tm = bv_->textMetrics(text());
+       TextMetrics & tm = bv_->textMetrics(text());
        ParagraphMetrics const & pm = tm.parMetrics(pit());
        int row;
        if (pos() && boundary())
@@ -1233,13 +1235,13 @@ bool Cursor::upDownInText(bool up, bool & updateNeeded)
 
        // with and without selection are handled differently
        if (!selection()) {
-               int yo = bv_funcs::getPos(bv(), *this, boundary()).y_;
+               int yo = bv().getPos(*this, boundary()).y_;
                Cursor old = *this;
                // To next/previous row
                if (up)
-                       text()->editXY(*this, xo, yo - textRow().ascent() - 1);
+                       tm.editXY(*this, xo, yo - textRow().ascent() - 1);
                else
-                       text()->editXY(*this, xo, yo + textRow().descent() + 1);
+                       tm.editXY(*this, xo, yo + textRow().descent() + 1);
                clearSelection();
                
                // This happens when you move out of an inset.
@@ -1437,7 +1439,7 @@ void Cursor::noUpdate()
 
 Font Cursor::getFont() const
 {
-       // The logic here should more or less match to the Text::setCurrentFont
+       // The logic here should more or less match to the Cursor::setCurrentFont
        // logic, i.e. the cursor height should give a hint what will happen
        // if a character is entered.
        
@@ -1459,9 +1461,10 @@ Font Cursor::getFont() const
        
        // on space? Take the font before (only for RTL boundary stay)
        if (pos > 0) {
+               TextMetrics const & tm = bv().textMetrics(&text);
                if (pos == sl.lastpos()
-                               || (par.isSeparator(pos) &&
-                                               !text.isRTLBoundary(buffer(), par, pos)))
+                       || (par.isSeparator(pos) 
+                       && !tm.isRTLBoundary(sl.pit(), pos)))
                        --pos;
        }
        
@@ -1504,4 +1507,49 @@ bool notifyCursorLeaves(DocIterator const & old, Cursor & cur)
 }
 
 
+void Cursor::setCurrentFont()
+{
+       CursorSlice const & cs = innerTextSlice();
+       Paragraph const & par = cs.paragraph();
+       pos_type cpit = cs.pit();
+       pos_type cpos = cs.pos();
+       Text const & ctext = *cs.text();
+       TextMetrics const & tm = bv().textMetrics(&ctext);
+
+       // are we behind previous char in fact? -> go to that char
+       if (cpos > 0 && boundary())
+               --cpos;
+
+       // find position to take the font from
+       if (cpos != 0) {
+               // paragraph end? -> font of last char
+               if (cpos == lastpos())
+                       --cpos;
+               // on space? -> look at the words in front of space
+               else if (cpos > 0 && par.isSeparator(cpos))     {
+                       // abc| def -> font of c
+                       // abc |[WERBEH], i.e. boundary==true -> font of c
+                       // abc [WERBEH]| def, font of the space
+                       if (!tm.isRTLBoundary(cpit, cpos))
+                               --cpos;
+               }
+       }
+
+       // get font
+       BufferParams const & bufparams = buffer().params();
+       current_font = par.getFontSettings(bufparams, cpos);
+       real_current_font = tm.getDisplayFont(cpit, cpos);
+
+       // special case for paragraph end
+       if (cs.pos() == lastpos()
+           && tm.isRTLBoundary(cpit, cs.pos())
+           && !boundary()) {
+               Language const * lang = par.getParLanguage(bufparams);
+               current_font.setLanguage(lang);
+               current_font.setNumber(Font::OFF);
+               real_current_font.setLanguage(lang);
+               real_current_font.setNumber(Font::OFF);
+       }
+}
+
 } // namespace lyx