]> git.lyx.org Git - lyx.git/blobdiff - src/Text2.cpp
Further to r26743, add CustomPars and ForcePlain layout tags to InsetLayout,
[lyx.git] / src / Text2.cpp
index 1e2a88df5c0117ad70cedccc4914166e2bbc1d94..de328e3e2a4a32537f17a283aa064c69e34eded3 100644 (file)
@@ -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();
@@ -104,7 +117,13 @@ FontInfo Text::labelFont(Buffer const & buffer, Paragraph const & par) const
                // In case the default family has been customized
                if (layout.labelfont.family() == INHERIT_FAMILY)
                        lf.setFamily(buffer.params().getFont().fontInfo().family());
-               return lf;
+               // FIXME As above....
+               InsetCollapsable const * icp = par.inInset().asInsetCollapsable();
+               if (!icp)
+                       return lf;
+               FontInfo icf = icp->getLayout().labelfont();
+               icf.realize(lf);
+               return icf;
        }
 
        FontInfo font = layout.labelfont;
@@ -178,7 +197,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,22 +235,6 @@ 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;
@@ -386,8 +389,7 @@ void Text::toggleFree(Cursor & cur, Font const & font, bool toggleall)
 {
        LASSERT(this == cur.text(), /**/);
        // If the mask is completely neutral, tell user
-       if (font.fontInfo() == ignore_font && 
-               (font.language() == 0 || font.language() == ignore_language)) {
+       if (font.fontInfo() == ignore_font && font.language() == ignore_language) {
                // Could only happen with user style
                cur.message(_("No font change defined."));
                return;