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"
34 /* FIXME: toc types are currently identified by strings. It cannot be converted
35 * into an enum because of the user-configurable indexing categories and
36 * the user-definable float types provided by layout files.
38 * I leave this for documentation purposes for the moment.
41 TABLE_OF_CONTENTS,//"tableofcontents"
51 MARGINAL_NOTE,//"marginalnote"
52 INDEX,//"index", "index:<user-str>" (from interface)
55 FLOAT,//"figure", "table", "algorithm", user-defined (from layout?)
56 MATH_MACRO,//"math-macro"
58 SENSELESS,//"senseless"
68 friend class TocBackend;
69 friend class TocBuilder;
72 /// Default constructor for STL containers.
73 TocItem() : dit_(0), depth_(0), output_(false) {}
75 TocItem(DocIterator const & dit,
79 docstring const & t = docstring(),
80 FuncRequest action = FuncRequest(LFUN_UNKNOWN_ACTION));
86 int depth() const { return depth_; }
88 docstring const & str() const { return str_; }
90 void str(docstring const & s) { str_ = s; }
92 docstring const & tooltip() const;
93 /// String for display, e.g. it has a mark if output is inactive
94 docstring const asString() const;
96 DocIterator const & dit() const { return dit_; }
98 bool isOutput() const { return output_; }
100 void setAction(FuncRequest a) { action_ = a; }
101 /// custom action, or the default one (paragraph-goto) if not customised
102 FuncRequest action() const;
105 /// Current position of item.
113 /// The tooltip string
115 /// Is this item in a note, inactive branch, etc?
122 /// Caption-enabled TOC builders
126 TocBuilder(std::shared_ptr<Toc> const toc);
127 /// When entering a float
128 void pushItem(DocIterator const & dit, docstring const & s,
129 bool output_active, bool is_captioned = false);
130 /// When encountering a caption
131 void captionItem(DocIterator const & dit, docstring const & s,
133 /// When exiting a float
143 std::shared_ptr<Toc> const toc_;
145 std::stack<frame> stack_;
149 /// Class to build and access the Tocs of a particular buffer.
153 static Toc::const_iterator findItem(Toc const & toc,
154 DocIterator const & dit);
155 /// Look for a TocItem given its depth and string.
156 /// \return The first matching item.
157 /// \retval end() if no item was found.
158 static Toc::iterator findItem(Toc & toc, int depth, docstring const & str);
160 TocBackend(Buffer const * buffer) : buffer_(buffer) {}
162 void setBuffer(Buffer const * buffer) { buffer_ = buffer; }
164 void update(bool output_active, UpdateType utype);
165 /// \return true if the item was updated.
166 bool updateItem(DocIterator const & pit);
168 TocList const & tocs() const { return tocs_; }
170 std::shared_ptr<Toc const> toc(std::string const & type) const;
172 std::shared_ptr<Toc> toc(std::string const & type);
173 /// \return the current TocBuilder for the Toc of type \param type, or
174 /// creates one if it does not already exist.
175 TocBuilder & builder(std::string const & type);
176 /// \return the first Toc Item before the cursor.
177 /// \param type: Type of Toc.
178 /// \param dit: The cursor location in the document.
180 item(std::string const & type, DocIterator const & dit) const;
183 void writePlaintextTocList(std::string const & type,
184 odocstringstream & os, size_t max_length) const;
186 docstring outlinerName(std::string const & type) const;
192 std::map<std::string, unique_ptr<TocBuilder>> builders_;
194 Buffer const * buffer_;
200 #endif // TOC_BACKEND_H