+void InsetIndex::getSortkey(otexstream & os, OutputParams const & runparams) const
+{
+ Paragraph const & par = paragraphs().front();
+ InsetList::const_iterator it = par.insetList().begin();
+ for (; it != par.insetList().end(); ++it) {
+ Inset & inset = *it->inset;
+ if (inset.lyxCode() == INDEXMACRO_SORTKEY_CODE) {
+ InsetIndexMacro const & iim =
+ static_cast<InsetIndexMacro const &>(inset);
+ iim.getLatex(os, runparams);
+ return;
+ }
+ }
+}
+
+
+docstring InsetIndex::getSortkeyAsText(OutputParams const & runparams) const
+{
+ Paragraph const & par = paragraphs().front();
+ InsetList::const_iterator it = par.insetList().begin();
+ for (; it != par.insetList().end(); ++it) {
+ Inset & inset = *it->inset;
+ if (inset.lyxCode() == INDEXMACRO_SORTKEY_CODE) {
+ otexstringstream os;
+ InsetIndexMacro const & iim =
+ static_cast<InsetIndexMacro const &>(inset);
+ iim.getLatex(os, runparams);
+ return os.str();
+ }
+ }
+ return from_ascii("");
+}
+
+
+void InsetIndex::getSubentries(otexstream & os, OutputParams const & runparams) const
+{
+ Paragraph const & par = paragraphs().front();
+ InsetList::const_iterator it = par.insetList().begin();
+ int i = 0;
+ for (; it != par.insetList().end(); ++it) {
+ Inset & inset = *it->inset;
+ if (inset.lyxCode() == INDEXMACRO_CODE) {
+ InsetIndexMacro const & iim =
+ static_cast<InsetIndexMacro const &>(inset);
+ if (iim.params().type == InsetIndexMacroParams::Subindex) {
+ ++i;
+ if (i > 2)
+ return;
+ os << "!";
+ iim.getLatex(os, runparams);
+ }
+ }
+ }
+}
+
+
+std::vector<docstring> InsetIndex::getSubentriesAsText(OutputParams const & runparams) const
+{
+ std::vector<docstring> subentries;
+
+ Paragraph const & par = paragraphs().front();
+ InsetList::const_iterator it = par.insetList().begin();
+ int i = 0;
+ for (; it != par.insetList().end(); ++it) {
+ Inset & inset = *it->inset;
+ if (inset.lyxCode() == INDEXMACRO_CODE) {
+ InsetIndexMacro const & iim =
+ static_cast<InsetIndexMacro const &>(inset);
+ if (iim.params().type == InsetIndexMacroParams::Subindex) {
+ ++i;
+ if (i > 2)
+ break;
+
+ otexstringstream os;
+ iim.getLatex(os, runparams);
+ subentries.emplace_back(os.str());
+ }
+ }
+ }
+
+ return subentries;
+}
+
+
+docstring InsetIndex::getMainSubentryAsText(OutputParams const & runparams) const
+{
+ otexstringstream os;
+ InsetText::latex(os, runparams);
+ return os.str();
+}
+
+
+void InsetIndex::getSeeRefs(otexstream & os, OutputParams const & runparams) const
+{
+ Paragraph const & par = paragraphs().front();
+ InsetList::const_iterator it = par.insetList().begin();
+ for (; it != par.insetList().end(); ++it) {
+ Inset & inset = *it->inset;
+ if (inset.lyxCode() == INDEXMACRO_CODE) {
+ InsetIndexMacro const & iim =
+ static_cast<InsetIndexMacro const &>(inset);
+ if (iim.params().type == InsetIndexMacroParams::See
+ || iim.params().type == InsetIndexMacroParams::Seealso) {
+ iim.getLatex(os, runparams);
+ return;
+ }
+ }
+ }
+}
+
+
+docstring InsetIndex::getSeeAsText(OutputParams const & runparams) const
+{
+ Paragraph const & par = paragraphs().front();
+ InsetList::const_iterator it = par.insetList().begin();
+ for (; it != par.insetList().end(); ++it) {
+ Inset & inset = *it->inset;
+ if (inset.lyxCode() == INDEXMACRO_CODE) {
+ InsetIndexMacro const & iim =
+ static_cast<InsetIndexMacro const &>(inset);
+ if (iim.params().type == InsetIndexMacroParams::See) {
+ otexstringstream os;
+ iim.getLatex(os, runparams);
+ return os.str();
+ }
+ }
+ }
+ return from_ascii("");
+}
+
+
+std::vector<docstring> InsetIndex::getSeeAlsoesAsText(OutputParams const & runparams) const
+{
+ std::vector<docstring> seeAlsoes;
+
+ Paragraph const & par = paragraphs().front();
+ InsetList::const_iterator it = par.insetList().begin();
+ for (; it != par.insetList().end(); ++it) {
+ Inset & inset = *it->inset;
+ if (inset.lyxCode() == INDEXMACRO_CODE) {
+ InsetIndexMacro const & iim =
+ static_cast<InsetIndexMacro const &>(inset);
+ if (iim.params().type == InsetIndexMacroParams::Seealso) {
+ otexstringstream os;
+ iim.getLatex(os, runparams);
+ seeAlsoes.emplace_back(os.str());
+ }
+ }
+ }
+
+ return seeAlsoes;
+}
+
+
+namespace {
+
+bool hasInsetWithCode(const InsetIndex * const inset_index, const InsetCode code,
+ const std::set<InsetIndexMacroParams::Type> types = {})
+{
+ Paragraph const & par = inset_index->paragraphs().front();
+ InsetList::const_iterator it = par.insetList().begin();
+ for (; it != par.insetList().end(); ++it) {
+ Inset & inset = *it->inset;
+ if (inset.lyxCode() == code) {
+ if (types.empty())
+ return true;
+
+ LASSERT(code == INDEXMACRO_CODE, return false);
+ InsetIndexMacro const & iim =
+ static_cast<InsetIndexMacro const &>(inset);
+ if (types.find(iim.params().type) != types.end())
+ return true;
+ }
+ }
+ return false;
+}
+
+} // namespace
+
+
+bool InsetIndex::hasSubentries() const
+{
+ return hasInsetWithCode(this, INDEXMACRO_CODE, {InsetIndexMacroParams::Subindex});
+}
+
+
+bool InsetIndex::hasSeeRef() const
+{
+ return hasInsetWithCode(this, INDEXMACRO_CODE, {InsetIndexMacroParams::See, InsetIndexMacroParams::Seealso});
+}
+
+
+bool InsetIndex::hasSortKey() const
+{
+ return hasInsetWithCode(this, INDEXMACRO_SORTKEY_CODE);
+}
+
+
+bool InsetIndex::macrosPossible(string const type) const
+{
+ if (type != "see" && type != "seealso"
+ && type != "sortkey" && type != "subindex")
+ return false;
+
+ Paragraph const & par = paragraphs().front();
+ InsetList::const_iterator it = par.insetList().begin();
+ int subidxs = 0;
+ for (; it != par.insetList().end(); ++it) {
+ Inset & inset = *it->inset;
+ if (type == "sortkey" && inset.lyxCode() == INDEXMACRO_SORTKEY_CODE)
+ return false;
+ if (inset.lyxCode() == INDEXMACRO_CODE) {
+ InsetIndexMacro const & iim = static_cast<InsetIndexMacro const &>(inset);
+ if ((type == "see" || type == "seealso")
+ && (iim.params().type == InsetIndexMacroParams::See
+ || iim.params().type == InsetIndexMacroParams::Seealso))
+ return false;
+ if (type == "subindex"
+ && iim.params().type == InsetIndexMacroParams::Subindex) {
+ ++subidxs;
+ if (subidxs > 1)
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+