]> 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 71bc8ae80e72290076f0f859c8ad2e8eca9bc38c..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,7 +74,8 @@ using graphics::PreviewLoader;
 InsetText::InsetText(Buffer const & buf)
        : drawFrame_(false), frame_color_(Color_insetframe)
 {
-       initParagraphs(buf);
+       setBuffer(const_cast<Buffer &>(buf));
+       initParagraphs();
 }
 
 
@@ -88,10 +90,6 @@ InsetText::InsetText(InsetText const & in)
 }
 
 
-InsetText::InsetText()
-{}
-
-
 void InsetText::setBuffer(Buffer & buf)
 {
        ParagraphList::iterator end = paragraphs().end();
@@ -101,16 +99,16 @@ void InsetText::setBuffer(Buffer & buf)
 }
 
 
-void InsetText::initParagraphs(Buffer const & buf)
+void InsetText::initParagraphs()
 {
        LASSERT(paragraphs().empty(), /**/);
-       buffer_ = const_cast<Buffer *>(&buf);
        paragraphs().push_back(Paragraph());
        Paragraph & ourpar = paragraphs().back();
-       ourpar.setPlainOrDefaultLayout(buf.params().documentClass());
        ourpar.setInsetOwner(this);
+       ourpar.setDefaultLayout(buffer_->params().documentClass());
 }
 
+
 void InsetText::setParagraphOwner()
 {
        for_each(paragraphs().begin(), paragraphs().end(),
@@ -202,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;
 }
 
 
@@ -253,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);
+       }
 }
 
 
@@ -439,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;
        }
 }
@@ -485,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:
@@ -498,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());
        }
 }