]> 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 1eb62afab1340c54782742d9c57e85741a3b8076..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)
@@ -50,74 +49,46 @@ int InsetIndex::docbook(Buffer const & buf, odocstream & os,
 }
 
 
-Inset::Code InsetIndex::lyxCode() const
-{
-       return Inset::INDEX_CODE;
-}
-
-
 Inset * InsetIndex::clone() const
 {
        return new InsetIndex(*this);
 }
 
 
-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
+void InsetIndex::addToToc(Buffer const & buf,
+       ParConstIterator const & cpit) const
 {
-       Font tmpfont = mi.base.font;
-       getDrawFont(mi.base.font);
-       mi.base.font.realize(tmpfont);
-       InsetCollapsable::metrics(mi, dim);
-       mi.base.font = tmpfont;
-}
-
+       ParConstIterator pit = cpit;
+       pit.push_back(*this);
 
-void InsetIndex::draw(PainterInfo & pi, int x, int y) const
-{
-       Font tmpfont = pi.base.font;
-       getDrawFont(pi.base.font);
-       pi.base.font.realize(tmpfont);
-       InsetCollapsable::draw(pi, x, y);
-       pi.base.font = tmpfont;
+       Toc & toc = buf.tocBackend().toc("index");
+       docstring str;
+       str = getNewLabel(str);
+       toc.push_back(TocItem(pit, 0, str));
 }
 
 
-void InsetIndex::getDrawFont(Font & font) const
-{
-       font = Font(Font::ALL_INHERIT);
-       font.realize(layout_.font);
-}
+InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
+       : InsetCommand(p, string())
+{}
 
 
-bool InsetIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
-       FuncStatus & status) const
+CommandInfo const * InsetPrintIndex::findInfo(string const & /* cmdName */)
 {
-       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);
-               }
+       static const char * const paramnames[] = {"name", ""};
+       static const bool isoptional[] = {false};
+       static const CommandInfo info = {1, paramnames, isoptional};
+       return &info;
 }
 
 
-
-InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
-       : InsetCommand(p, string())
-{}
-
-
 docstring const InsetPrintIndex::getScreenLabel(Buffer const &) const
 {
        return _("Index");
@@ -130,10 +101,9 @@ void InsetPrintIndex::validate(LaTeXFeatures & features) const
 }
 
 
-Inset::Code InsetPrintIndex::lyxCode() const
+InsetCode InsetPrintIndex::lyxCode() const
 {
-       return Inset::INDEX_PRINT_CODE;
+       return INDEX_PRINT_CODE;
 }
 
-
 } // namespace lyx