]> git.lyx.org Git - features.git/blobdiff - src/insets/InsetText.cpp
move more stuff from buffer_func to Buffer
[features.git] / src / insets / InsetText.cpp
index 56e9d8f0318f7995c74bbbb687742e682d185fb0..078d8154dbca4a0b4c76c6f32d357aaadcbfb0a4 100644 (file)
@@ -3,7 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author Jürgen Vigna
+ * \author Jürgen Vigna
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -25,6 +25,7 @@
 #include "DispatchResult.h"
 #include "ErrorList.h"
 #include "FuncRequest.h"
+#include "FuncStatus.h"
 #include "InsetList.h"
 #include "Intl.h"
 #include "Lexer.h"
@@ -73,8 +74,8 @@ using graphics::PreviewLoader;
 InsetText::InsetText(Buffer const & buf)
        : drawFrame_(false), frame_color_(Color_insetframe)
 {
-       initParagraphs(buf.params());
        setBuffer(const_cast<Buffer &>(buf));
+       initParagraphs();
 }
 
 
@@ -98,13 +99,13 @@ void InsetText::setBuffer(Buffer & buf)
 }
 
 
-void InsetText::initParagraphs(BufferParams const & bparams)
+void InsetText::initParagraphs()
 {
        LASSERT(paragraphs().empty(), /**/);
        paragraphs().push_back(Paragraph());
        Paragraph & ourpar = paragraphs().back();
        ourpar.setInsetOwner(this);
-       ourpar.setPlainOrDefaultLayout(bparams.documentClass());
+       ourpar.setDefaultLayout(buffer_->params().documentClass());
 }
 
 
@@ -199,11 +200,18 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const
                int const h = tm.height() + 2 * TEXT_TO_INSET_OFFSET;
                int const xframe = x + TEXT_TO_INSET_OFFSET / 2;
                if (pi.full_repaint)
-                       pi.pain.fillRectangle(xframe, yframe, w, h, backgroundColor());
+                       pi.pain.fillRectangle(xframe, yframe, w, h,
+                               pi.backgroundColor(this));
+
                if (drawFrame_)
                        pi.pain.rectangle(xframe, yframe, w, h, frameColor());
        }
+       ColorCode const old_color = pi.background_color;
+       pi.background_color = pi.backgroundColor(this, false);
+
        tm.draw(pi, x + TEXT_TO_INSET_OFFSET, y);
+
+       pi.background_color = old_color;
 }
 
 
@@ -250,7 +258,21 @@ void InsetText::doDispatch(Cursor & cur, FuncRequest & cmd)
 bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd,
        FuncStatus & status) const
 {
-       return text_.getStatus(cur, cmd, status);
+       switch (cmd.action) {
+       case LFUN_LAYOUT:
+               status.setEnabled(!forcePlainLayout());
+               return true;
+
+       case LFUN_LAYOUT_PARAGRAPH:
+       case LFUN_PARAGRAPH_PARAMS:
+       case LFUN_PARAGRAPH_PARAMS_APPLY:
+       case LFUN_PARAGRAPH_SPACING:
+       case LFUN_PARAGRAPH_UPDATE:
+               status.setEnabled(allowParagraphCustomization());
+               return true;
+       default:
+               return text_.getStatus(cur, cmd, status);
+       }
 }
 
 
@@ -436,13 +458,13 @@ void InsetText::updateLabels(ParIterator const & it)
 {
        ParIterator it2 = it;
        it2.forwardPos();
-       LASSERT(&it2.inset() == this && it2.pit() == 0, /**/);
-       if (producesOutput())
-               lyx::updateLabels(buffer(), it2);
-       else {
-               DocumentClass const & tclass = buffer().params().documentClass();
+       LASSERT(&it2.inset() == this && it2.pit() == 0, return);
+       if (producesOutput()) {
+               buffer().updateLabels(it2);
+       else {
+               DocumentClass const & tclass = buffer().masterBuffer()->params().documentClass();
                Counters const savecnt = tclass.counters();
-               lyx::updateLabels(buffer(), it2);
+               buffer().updateLabels(it2);
                tclass.counters() = savecnt;
        }
 }
@@ -482,7 +504,7 @@ void InsetText::addToToc(DocIterator const & cdit)
                                        *static_cast<InsetOptArg&>(inset).paragraphs().begin();
                                if (!par.labelString().empty())
                                        tocstring = par.labelString() + ' ';
-                               tocstring += insetpar.asString();
+                               tocstring += insetpar.asString(AS_STR_INSETS);
                                break;
                        }
                        default:
@@ -495,9 +517,12 @@ void InsetText::addToToc(DocIterator const & cdit)
                        dit.pos() = 0;
                        // insert this into the table of contents
                        if (tocstring.empty())
-                               tocstring = par.asString(AS_STR_LABEL);
+                               tocstring = par.asString(AS_STR_LABEL | AS_STR_INSETS);
                        toc.push_back(TocItem(dit, toclevel - min_toclevel, tocstring));
                }
+               
+               // And now the list of changes.
+               par.addChangesToToc(dit, buffer());
        }
 }