]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetIndex.cpp
This should be the last of the commits refactoring the InsetLayout code.
[lyx.git] / src / insets / InsetIndex.cpp
index 41c1d0dd8c7060e233e257c681a1af8fba97a82d..e46e6cea8016168a921ddad2c26523f53ba7f0a1 100644 (file)
 
 #include "InsetIndex.h"
 
+#include "Buffer.h"
 #include "DispatchResult.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
-#include "gettext.h"
 #include "LaTeXFeatures.h"
 #include "MetricsInfo.h"
 #include "sgml.h"
+#include "TocBackend.h"
 
-#include "support/std_ostream.h"
+#include "support/gettext.h"
 
+#include <ostream>
 
-namespace lyx {
+using namespace std;
 
-using std::string;
-using std::ostream;
+namespace lyx {
 
 
 InsetIndex::InsetIndex(BufferParams const & bp)
        : InsetCollapsable(bp)
-{
-       setLayout(bp);
-}
+{}
 
 
 InsetIndex::InsetIndex(InsetIndex const & in)
@@ -56,63 +55,32 @@ Inset * InsetIndex::clone() const
 }
 
 
-void InsetIndex::write(Buffer const & buf, std::ostream & os) const
+void InsetIndex::write(Buffer const & buf, ostream & os) const
 {
        os << to_utf8(name()) << "\n";
        InsetCollapsable::write(buf, os);
 }
 
 
-void InsetIndex::metrics(MetricsInfo & mi, Dimension & dim) const
-{
-       FontInfo tmpfont = mi.base.font;
-       getDrawFont(mi.base.font);
-       mi.base.font.realize(tmpfont);
-       InsetCollapsable::metrics(mi, dim);
-       mi.base.font = tmpfont;
-}
-
-
-void InsetIndex::draw(PainterInfo & pi, int x, int y) const
+void InsetIndex::addToToc(Buffer const & buf,
+       ParConstIterator const & cpit) const
 {
-       FontInfo tmpfont = pi.base.font;
-       getDrawFont(pi.base.font);
-       pi.base.font.realize(tmpfont);
-       InsetCollapsable::draw(pi, x, y);
-       pi.base.font = tmpfont;
-}
-
+       ParConstIterator pit = cpit;
+       pit.push_back(*this);
 
-void InsetIndex::getDrawFont(FontInfo & font) const
-{
-       font = inherit_font;
-       font.realize(layout_.font);
+       Toc & toc = buf.tocBackend().toc("index");
+       docstring str;
+       str = getNewLabel(str);
+       toc.push_back(TocItem(pit, 0, str));
 }
 
 
-bool InsetIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
-       FuncStatus & status) const
-{
-       switch (cmd.action) {
-               // paragraph breaks not allowed
-               case LFUN_BREAK_PARAGRAPH:
-               case LFUN_BREAK_PARAGRAPH_SKIP:
-                       status.enabled(false);
-                       return true;
-
-               default:
-                       return InsetCollapsable::getStatus(cur, cmd, status);
-               }
-}
-
-
-
 InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
        : InsetCommand(p, string())
 {}
 
 
-CommandInfo const * InsetPrintIndex::findInfo(std::string const & /* cmdName */)
+CommandInfo const * InsetPrintIndex::findInfo(string const & /* cmdName */)
 {
        static const char * const paramnames[] = {"name", ""};
        static const bool isoptional[] = {false};
@@ -138,5 +106,4 @@ InsetCode InsetPrintIndex::lyxCode() const
        return INDEX_PRINT_CODE;
 }
 
-
 } // namespace lyx