4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Jean-Marc Lasgouttes
8 * \author Angus Leeming
9 * \author Abdelrazak Younes
10 * \author Guillaume Munch
12 * Full author contact details are available in file CREDITS.
18 #include "DocIterator.h"
19 #include "FuncRequest.h"
20 #include "OutputEnums.h"
23 #include "support/strfwd.h"
24 #include "support/unique_ptr.h"
33 /* Toc types are described by strings. They cannot be converted into an enum
34 * because of the user-configurable categories for index and the user-definable
35 * toc types provided in layout files.
37 * Here is a summary of built-in toc types
39 * Non-customizable (used without TocBuilder): "tableofcontents", "change",
40 * "citation", "label", "senseless".
42 * Built-in but customizable (used with TocBuilder): "child", "graphics",
43 * "equation", "index", "index:<user-str>", "nomencl", "listings", "math-macro",
44 * "external", any float type (as defined in the layouts).
46 * The following are used for XHTML output: "tableofcontents" (InsetText),
47 * "citation" (InsetCitation), any float type.
49 * Other types are defined in the layouts.
57 friend class TocBackend;
58 friend class TocBuilder;
61 /// Default constructor for STL containers.
62 TocItem() : dit_(0), depth_(0), output_(false) {}
64 TocItem(DocIterator const & dit,
68 FuncRequest action = FuncRequest(LFUN_UNKNOWN_ACTION)
75 int depth() const { return depth_; }
77 docstring const & str() const { return str_; }
79 void str(docstring const & s) { str_ = s; }
80 /// String for display, e.g. it has a mark if output is inactive
81 docstring const asString() const;
83 DocIterator const & dit() const { return dit_; }
85 bool isOutput() const { return output_; }
87 void setAction(FuncRequest a) { action_ = a; }
88 /// custom action, or the default one (paragraph-goto) if not customised
89 FuncRequest action() const;
92 /// Current position of item.
100 /// Is this item in a note, inactive branch, etc?
107 /// Caption-enabled TOC builders
111 TocBuilder(std::shared_ptr<Toc> toc);
112 /// When entering a float or flex or paragraph (with AddToToc)
113 void pushItem(DocIterator const & dit, docstring const & s,
114 bool output_active, bool is_captioned = false);
115 /// When encountering a float caption
116 void captionItem(DocIterator const & dit, docstring const & s,
118 /// When encountering an argument (with isTocCaption) for flex or paragraph
119 void argumentItem(docstring const & arg_str);
120 /// When exiting a float or flex or paragraph
130 std::shared_ptr<Toc> const toc_;
132 std::stack<frame> stack_;
136 /// Class to build and access the Tocs of a particular buffer.
140 static Toc::const_iterator findItem(Toc const & toc,
141 DocIterator const & dit);
142 /// Look for a TocItem given its depth and string.
143 /// \return The first matching item.
144 /// \retval end() if no item was found.
145 static Toc::iterator findItem(Toc & toc, int depth, docstring const & str);
147 TocBackend(Buffer const * buffer) : buffer_(buffer) {}
149 void setBuffer(Buffer const * buffer) { buffer_ = buffer; }
151 void update(bool output_active, UpdateType utype);
152 /// \return true if the item was updated.
153 bool updateItem(DocIterator const & pit);
155 TocList const & tocs() const { return tocs_; }
157 std::shared_ptr<Toc const> toc(std::string const & type) const;
159 std::shared_ptr<Toc> toc(std::string const & type);
160 /// \return the current TocBuilder for the Toc of type \param type, or
161 /// creates one if it does not already exist.
162 TocBuilder & builder(std::string const & type);
163 /// \return the first Toc Item before the cursor.
164 /// \param type: Type of Toc.
165 /// \param dit: The cursor location in the document.
167 item(std::string const & type, DocIterator const & dit) const;
170 void writePlaintextTocList(std::string const & type,
171 odocstringstream & os, size_t max_length) const;
173 docstring outlinerName(std::string const & type) const;
174 /// Whether a toc type is less important and appears in the "Other lists"
176 static bool isOther(std::string const & type);
182 std::map<std::string, unique_ptr<TocBuilder>> builders_;
184 Buffer const * buffer_;
190 #endif // TOC_BACKEND_H