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"
22 #include "support/shared_ptr.h"
23 #include "support/strfwd.h"
36 /* FIXME: toc types are currently identified by strings. It cannot be converted
37 * into an enum because of the user-configurable indexing categories and
38 * the user-definable float types provided by layout files.
40 * I leave this for documentation purposes for the moment.
43 TABLE_OF_CONTENTS,//"tableofcontents"
53 MARGINAL_NOTE,//"marginalnote"
54 INDEX,//"index", "index:<user-str>" (from interface)
57 FLOAT,//"figure", "table", "algorithm", user-defined (from layout?)
58 MATH_MACRO,//"math-macro"
60 SENSELESS,//"senseless"
71 friend class TocBackend;
72 friend class TocBuilder;
75 /// Default constructor for STL containers.
76 TocItem() : dit_(0), depth_(0), output_(false) {}
78 TocItem(DocIterator const & dit,
82 docstring const & t = docstring(),
83 FuncRequest action = FuncRequest(LFUN_UNKNOWN_ACTION)
90 int depth() const { return depth_; }
92 docstring const & str() const { return str_; }
94 void str(docstring const & s) { str_ = s; }
96 docstring const & tooltip() const;
97 /// String for display, e.g. it has a mark if output is inactive
98 docstring const asString() const;
100 DocIterator const & dit() const { return dit_; }
102 bool isOutput() const { return output_; }
104 void setAction(FuncRequest a) { action_ = a; }
105 /// custom action, or the default one (paragraph-goto) if not customised
106 FuncRequest action() const;
109 /// Current position of item.
117 /// The tooltip string
119 /// Is this item in a note, inactive branch, etc?
127 class Toc : public std::vector<TocItem>
130 // This is needed to work around a libc++ bug
131 // https://llvm.org/bugs/show_bug.cgi?id=24137
133 typedef std::vector<TocItem>::const_iterator const_iterator;
134 typedef std::vector<TocItem>::iterator iterator;
135 const_iterator item(DocIterator const & dit) const;
136 /// Look for a TocItem given its depth and string.
137 /// \return The first matching item.
138 /// \retval end() if no item was found.
139 iterator item(int depth, docstring const & str);
142 typedef Toc::const_iterator TocIterator;
145 /// Caption-enabled TOC builders
149 TocBuilder(shared_ptr<Toc> const toc);
150 /// When entering a float
151 void pushItem(DocIterator const & dit, docstring const & s,
152 bool output_active, bool is_captioned = false);
153 /// When encountering a caption
154 void captionItem(DocIterator const & dit, docstring const & s,
156 /// When exiting a float
166 shared_ptr<Toc> const toc_;
168 std::stack<frame> stack_;
173 /// A class and no typedef because we want to forward declare it.
174 class TocList : public std::map<std::string, shared_ptr<Toc> >
177 // this can create null pointers
178 using std::map<std::string, shared_ptr<Toc> >::operator[];
183 class TocBuilderStore
186 TocBuilderStore() {};
188 shared_ptr<TocBuilder> get(std::string const & type, shared_ptr<Toc> toc);
190 void clear() { map_.clear(); };
192 typedef std::map<std::string, shared_ptr<TocBuilder> > map_t;
204 TocBackend(Buffer const * buffer) : buffer_(buffer) {}
206 void setBuffer(Buffer const * buffer) { buffer_ = buffer; }
208 void update(bool output_active, UpdateType utype);
209 /// \return true if the item was updated.
210 bool updateItem(DocIterator const & pit);
212 TocList const & tocs() const { return tocs_; }
214 shared_ptr<Toc const> toc(std::string const & type) const;
215 shared_ptr<Toc> toc(std::string const & type);
217 shared_ptr<TocBuilder> builder(std::string const & type);
218 /// Return the first Toc Item before the cursor
220 std::string const & type, ///< Type of Toc.
221 DocIterator const & dit ///< The cursor location in the document.
225 void writePlaintextTocList(std::string const & type,
226 odocstringstream & os, size_t max_length) const;
228 docstring outlinerName(std::string const & type) const;
234 TocBuilderStore builders_;
236 Buffer const * buffer_;
242 #endif // TOC_BACKEND_H