]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
minimal effort implementation of:
[lyx.git] / src / text2.C
index 3df5592a45e34372c377a3fc09d92634deabfd0a..ce1529d9b3e74d18a48a767a59182c269562674a 100644 (file)
@@ -57,6 +57,7 @@
 
 #include <sstream>
 
+using lyx::docstring;
 using lyx::pit_type;
 using lyx::pos_type;
 
@@ -89,8 +90,7 @@ void LyXText::init(BufferView * bv)
        for (pit_type pit = 0; pit != end; ++pit)
                pars_[pit].rows().clear();
 
-       current_font = getFont(pars_[0], 0);
-       updateCounters(*bv->buffer());
+       updateLabels(*bv->buffer());
 }
 
 
@@ -173,10 +173,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 +212,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 +243,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 +264,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 +364,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);
@@ -358,7 +379,7 @@ void LyXText::setLayout(LCursor & cur, string const & layout)
        pit_type undopit = undoSpan(end - 1);
        recUndo(start, undopit - 1);
        setLayout(start, end, layout);
-       updateCounters(cur.buffer());
+       updateLabels(cur.buffer());
 }
 
 
@@ -385,6 +406,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);
@@ -419,7 +444,7 @@ void LyXText::changeDepth(LCursor & cur, DEPTH_CHANGE type)
        }
        // this handles the counter labels, and also fixes up
        // depth values for follow-on (child) paragraphs
-       updateCounters(cur.buffer());
+       updateLabels(cur.buffer());
 }
 
 
@@ -648,7 +673,7 @@ void LyXText::insertStringAsParagraphs(LCursor & cur, string const & str)
                                linestr[i] = ' ';
                                newline_inserted = true;
                        }
-               } else if (IsPrintable(linestr[i])) {
+               } else if (isPrintable(linestr[i])) {
                        newline_inserted = false;
                }
        }
@@ -776,8 +801,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);
                }
@@ -1274,7 +1301,11 @@ bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old)
                                cur.resetAnchor();
                        }
                }
-               updateCounters(old.buffer());
+               // There is a crash reported by Edwin Leuven (16/04/2006) because of:
+               //ParIterator par_it(old);
+               //updateLabels(old.buffer(), par_it);
+               // So for now we do the full update:
+               updateLabels(old.buffer());
                return true;
        }