]> git.lyx.org Git - features.git/blobdiff - src/Text2.cpp
move updateLables to buffer
[features.git] / src / Text2.cpp
index dba04960533e0ee8a669c1028643b1734952a59e..a224dc75eb260b97b26b9f730e43c9b40e13747b 100644 (file)
@@ -4,16 +4,16 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Asger Alstrup
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
  * \author Alfredo Braunstein
  * \author Jean-Marc Lasgouttes
  * \author Angus Leeming
  * \author John Levon
- * \author André Pönitz
+ * \author André Pönitz
  * \author Allan Rae
  * \author Stefan Schimanski
  * \author Dekel Tsur
- * \author Jürgen Vigna
+ * \author Jürgen Vigna
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -46,7 +46,7 @@
 #include "TextMetrics.h"
 #include "VSpace.h"
 
-#include "insets/InsetEnvironment.h"
+#include "insets/InsetCollapsable.h"
 
 #include "mathed/InsetMathHull.h"
 
@@ -74,6 +74,7 @@ bool Text::isMainText(Buffer const & buffer) const
 }
 
 
+// Note that this is supposed to return a fully realized font.
 FontInfo Text::layoutFont(Buffer const & buffer, pit_type const pit) const
 {
        Layout const & layout = pars_[pit].layout();
@@ -83,7 +84,18 @@ FontInfo Text::layoutFont(Buffer const & buffer, pit_type const pit) const
                // In case the default family has been customized
                if (layout.font.family() == INHERIT_FAMILY)
                        lf.setFamily(buffer.params().getFont().fontInfo().family());
-               return lf;
+               // FIXME
+               // It ought to be possible here just to use Inset::getLayout() and skip
+               // the asInsetCollapsable() bit. Unfortunatley, that doesn't work right
+               // now, because Inset::getLayout() will return a default-constructed
+               // InsetLayout, and that e.g. sets the foreground color to red. So we
+               // need to do some work to make that possible.
+               InsetCollapsable const * icp = pars_[pit].inInset().asInsetCollapsable();
+               if (!icp)
+                       return lf;
+               FontInfo icf = icp->getLayout().font();
+               icf.realize(lf);
+               return icf;
        }
 
        FontInfo font = layout.font;
@@ -95,6 +107,7 @@ FontInfo Text::layoutFont(Buffer const & buffer, pit_type const pit) const
 }
 
 
+// Note that this is supposed to return a fully realized font.
 FontInfo Text::labelFont(Buffer const & buffer, Paragraph const & par) const
 {
        Layout const & layout = par.layout();
@@ -178,7 +191,7 @@ void Text::setInsetFont(BufferView const & bv, pit_type pit,
 // return past-the-last paragraph influenced by a layout change on pit
 pit_type Text::undoSpan(pit_type pit)
 {
-       pit_type end = paragraphs().size();
+       pit_type const end = paragraphs().size();
        pit_type nextpit = pit + 1;
        if (nextpit == end)
                return nextpit;
@@ -216,29 +229,13 @@ void Text::setLayout(Buffer const & buffer, pit_type start, pit_type end,
 void Text::setLayout(Cursor & cur, docstring const & layout)
 {
        LASSERT(this == cur.text(), /**/);
-       // special handling of new environment insets
-       BufferView & bv = cur.bv();
-       BufferParams const & params = bv.buffer().params();
-       Layout const & lyxlayout = params.documentClass()[layout];
-       if (lyxlayout.is_environment) {
-               // move everything in a new environment inset
-               LYXERR(Debug::DEBUG, "setting layout " << to_utf8(layout));
-               lyx::dispatch(FuncRequest(LFUN_LINE_BEGIN));
-               lyx::dispatch(FuncRequest(LFUN_LINE_END_SELECT));
-               lyx::dispatch(FuncRequest(LFUN_CUT));
-               Inset * inset = new InsetEnvironment(bv.buffer(), layout);
-               insertInset(cur, inset);
-               //inset->edit(cur, true);
-               //lyx::dispatch(FuncRequest(LFUN_PASTE));
-               return;
-       }
 
        pit_type start = cur.selBegin().pit();
        pit_type end = cur.selEnd().pit() + 1;
        pit_type undopit = undoSpan(end - 1);
        recUndo(cur, start, undopit - 1);
        setLayout(cur.buffer(), start, end, layout);
-       updateLabels(cur.buffer());
+       cur.buffer().updateLabels();
 }
 
 
@@ -297,7 +294,7 @@ void Text::changeDepth(Cursor & cur, DEPTH_CHANGE type)
        }
        // this handles the counter labels, and also fixes up
        // depth values for follow-on (child) paragraphs
-       updateLabels(cur.buffer());
+       cur.buffer().updateLabels();
 }