]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
cleanup after svn hang-up, #undef CursorShape. Should be compilable ganin now.
[lyx.git] / src / text2.C
index ad08cfca814ae54bdece3f41226973e7a2c69322..09b9a2ce93747ded3f0604b420cb6074e439c1fd 100644 (file)
 
 #include "insets/insetenv.h"
 
+#include "mathed/InsetMathHull.h"
+
 #include "support/textutils.h"
 
 #include <boost/current_function.hpp>
 
 #include <sstream>
 
+using lyx::docstring;
 using lyx::pit_type;
 using lyx::pos_type;
 
@@ -89,7 +92,6 @@ void LyXText::init(BufferView * bv)
        for (pit_type pit = 0; pit != end; ++pit)
                pars_[pit].rows().clear();
 
-       current_font = getFont(pars_[0], 0);
        updateLabels(*bv->buffer());
 }
 
@@ -173,10 +175,19 @@ LyXFont LyXText::getFont(Paragraph const & par, pos_type const pos) const
                LyXFont f = par.getFontSettings(params, pos);
                if (!isMainText())
                        applyOuterFont(f);
-               if (layout->labeltype == LABEL_MANUAL && pos < body_pos)
-                       return f.realize(layout->reslabelfont);
-               else
-                       return f.realize(layout->resfont);
+               LyXFont lf;
+               LyXFont rlf;
+               if (layout->labeltype == LABEL_MANUAL && pos < body_pos) {
+                       lf = layout->labelfont;
+                       rlf = layout->reslabelfont;
+               } else {
+                       lf = layout->font;
+                       rlf = layout->resfont;
+               }
+               // In case the default family has been customized
+               if (lf.family() == LyXFont::INHERIT_FAMILY)
+                       rlf.setFamily(params.getFont().family());
+               return f.realize(rlf);
        }
 
        // The uncommon case need not be optimized as much
@@ -203,7 +214,9 @@ LyXFont LyXText::getFont(Paragraph const & par, pos_type const pos) const
                        break;
                }
        // Realize against environment font information
-       if (pit < pars_.size())
+       // NOTE: the cast to pit_type should be removed when pit_type
+       // changes to a unsigned integer.
+       if (pit < pit_type(pars_.size()))
                font.realize(outerFont(pit, pars_));
 
        // Realize with the fonts of lesser depth.
@@ -232,8 +245,13 @@ LyXFont LyXText::getLayoutFont(pit_type const pit) const
 {
        LyXLayout_ptr const & layout = pars_[pit].layout();
 
-       if (!pars_[pit].getDepth())
-               return layout->resfont;
+       if (!pars_[pit].getDepth())  {
+               LyXFont lf = layout->resfont;
+               // In case the default family has been customized
+               if (layout->font.family() == LyXFont::INHERIT_FAMILY)
+                       lf.setFamily(bv()->buffer()->params().getFont().family());
+               return lf;
+       }
 
        LyXFont font = layout->font;
        // Realize with the fonts of lesser depth.
@@ -248,8 +266,13 @@ LyXFont LyXText::getLabelFont(Paragraph const & par) const
 {
        LyXLayout_ptr const & layout = par.layout();
 
-       if (!par.getDepth())
-               return layout->reslabelfont;
+       if (!par.getDepth()) {
+               LyXFont lf = layout->reslabelfont;
+               // In case the default family has been customized
+               if (layout->labelfont.family() == LyXFont::INHERIT_FAMILY)
+                       lf.setFamily(bv()->buffer()->params().getFont().family());
+               return lf;
+       }
 
        LyXFont font = layout->labelfont;
        // Realize with the fonts of lesser depth.
@@ -343,8 +366,8 @@ void LyXText::setLayout(LCursor & cur, string const & layout)
        if (lyxlayout->is_environment) {
                // move everything in a new environment inset
                lyxerr[Debug::DEBUG] << "setting layout " << layout << endl;
-               bv.owner()->dispatch(FuncRequest(LFUN_HOME));
-               bv.owner()->dispatch(FuncRequest(LFUN_ENDSEL));
+               bv.owner()->dispatch(FuncRequest(LFUN_LINE_BEGIN));
+               bv.owner()->dispatch(FuncRequest(LFUN_LINE_END_SELECT));
                bv.owner()->dispatch(FuncRequest(LFUN_CUT));
                InsetBase * inset = new InsetEnvironment(params, layout);
                insertInset(cur, inset);
@@ -385,6 +408,10 @@ bool changeDepthAllowed(LyXText::DEPTH_CHANGE type,
 bool LyXText::changeDepthAllowed(LCursor & cur, DEPTH_CHANGE type) const
 {
        BOOST_ASSERT(this == cur.text());
+       // this happens when selecting several cells in tabular (bug 2630)
+       if (cur.selBegin().idx() != cur.selEnd().idx())
+               return false;
+
        pit_type const beg = cur.selBegin().pit();
        pit_type const end = cur.selEnd().pit() + 1;
        int max_depth = (beg != 0 ? pars_[beg - 1].getMaxDepthAfter() : 0);
@@ -528,7 +555,7 @@ void LyXText::toggleFree(LCursor & cur, LyXFont const & font, bool toggleall)
        if (font == LyXFont(LyXFont::ALL_IGNORE)) {
                // Could only happen with user style
                cur.message(_("No font change defined. "
-                             "Use Character under the Layout menu to define font change."));
+                                          "Use Character under the Layout menu to define font change."));
                return;
        }
 
@@ -558,10 +585,10 @@ string LyXText::getStringToIndex(LCursor const & cur)
 {
        BOOST_ASSERT(this == cur.text());
 
-       string idxstring;
-       if (cur.selection()) {
+       docstring idxstring;
+       if (cur.selection())
                idxstring = cur.selectionAsString(false);
-       else {
+       else {
                // Try implicit word selection. If there is a change
                // in the language the implicit word selection is
                // disabled.
@@ -576,7 +603,7 @@ string LyXText::getStringToIndex(LCursor const & cur)
                        idxstring = tmpcur.selectionAsString(false);
        }
 
-       return idxstring;
+       return lyx::to_utf8(idxstring);
 }
 
 
@@ -622,7 +649,7 @@ void LyXText::insertInset(LCursor & cur, InsetBase * inset)
 
 
 // needed to insert the selection
-void LyXText::insertStringAsLines(LCursor & cur, string const & str)
+void LyXText::insertStringAsLines(LCursor & cur, docstring const & str)
 {
        cur.buffer().insertStringAsLines(pars_, cur.pit(), cur.pos(),
                                         current_font, str, autoBreakRows_);
@@ -631,9 +658,9 @@ void LyXText::insertStringAsLines(LCursor & cur, string const & str)
 
 // turn double CR to single CR, others are converted into one
 // blank. Then insertStringAsLines is called
-void LyXText::insertStringAsParagraphs(LCursor & cur, string const & str)
+void LyXText::insertStringAsParagraphs(LCursor & cur, docstring const & str)
 {
-       string linestr = str;
+       docstring linestr = str;
        bool newline_inserted = false;
 
        for (string::size_type i = 0, siz = linestr.size(); i < siz; ++i) {
@@ -692,6 +719,7 @@ void LyXText::setCursor(CursorSlice & cur, pit_type par, pos_type pos)
 void LyXText::setCursorIntern(LCursor & cur,
                              pit_type par, pos_type pos, bool setfont, bool boundary)
 {
+       BOOST_ASSERT(this == cur.text());
        cur.boundary(boundary);
        setCursor(cur.top(), par, pos);
        cur.setTargetX();
@@ -776,8 +804,10 @@ pos_type LyXText::getColumnNearX(pit_type const pit,
                c = bidi.vis2log(vc);
                last_tmpx = tmpx;
                if (body_pos > 0 && c == body_pos - 1) {
+                       string lsep = layout->labelsep;
+                       docstring dlsep(lsep.begin(), lsep.end());
                        tmpx += r.label_hfill +
-                               font_metrics::width(layout->labelsep, getLabelFont(par));
+                               font_metrics::width(dlsep, getLabelFont(par));
                        if (par.isLineSeparator(body_pos - 1))
                                tmpx -= singleWidth(par, body_pos - 1);
                }
@@ -1051,7 +1081,10 @@ bool LyXText::cursorUp(LCursor & cur)
        if (!cur.selection()) {
                int const y = bv_funcs::getPos(cur, cur.boundary()).y_;
                LCursor old = cur;
-               editXY(cur, x, y - par.rows()[row].ascent() - 1);
+               // Go to middle of previous row. 16 found to work OK;
+               // 12 = top/bottom margin of display math
+               int const margin = 3 * InsetMathHull::displayMargin() / 2;
+               editXY(cur, x, y - par.rows()[row].ascent() - margin);
                cur.clearSelection();
 
                // This happens when you move out of an inset.
@@ -1097,7 +1130,9 @@ bool LyXText::cursorDown(LCursor & cur)
        if (!cur.selection()) {
                int const y = bv_funcs::getPos(cur, cur.boundary()).y_;
                LCursor old = cur;
-               editXY(cur, x, y + par.rows()[row].descent() + 1);
+               // To middle of next row
+               int const margin = 3 * InsetMathHull::displayMargin() / 2;
+               editXY(cur, x, y + par.rows()[row].descent() + margin);
                cur.clearSelection();
 
                // This happens when you move out of an inset.