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"
28 using std::shared_ptr;
35 /* FIXME: toc types are currently identified by strings. It cannot be converted
36 * into an enum because of the user-configurable indexing categories and
37 * the user-definable float types provided by layout files.
39 * I leave this for documentation purposes for the moment.
42 TABLE_OF_CONTENTS,//"tableofcontents"
52 MARGINAL_NOTE,//"marginalnote"
53 INDEX,//"index", "index:<user-str>" (from interface)
56 FLOAT,//"figure", "table", "algorithm", user-defined (from layout?)
57 MATH_MACRO,//"math-macro"
59 SENSELESS,//"senseless"
69 friend class TocBackend;
70 friend class TocBuilder;
73 /// Default constructor for STL containers.
74 TocItem() : dit_(0), depth_(0), output_(false) {}
76 TocItem(DocIterator const & dit,
80 docstring const & t = docstring(),
81 FuncRequest action = FuncRequest(LFUN_UNKNOWN_ACTION)
88 int depth() const { return depth_; }
90 docstring const & str() const { return str_; }
92 void str(docstring const & s) { str_ = s; }
94 docstring const & tooltip() const;
95 /// String for display, e.g. it has a mark if output is inactive
96 docstring const asString() const;
98 DocIterator const & dit() const { return dit_; }
100 bool isOutput() const { return output_; }
102 void setAction(FuncRequest a) { action_ = a; }
103 /// custom action, or the default one (paragraph-goto) if not customised
104 FuncRequest action() const;
107 /// Current position of item.
115 /// The tooltip string
117 /// Is this item in a note, inactive branch, etc?
124 /// Caption-enabled TOC builders
128 TocBuilder(shared_ptr<Toc> const toc);
129 /// When entering a float
130 void pushItem(DocIterator const & dit, docstring const & s,
131 bool output_active, bool is_captioned = false);
132 /// When encountering a caption
133 void captionItem(DocIterator const & dit, docstring const & s,
135 /// When exiting a float
145 shared_ptr<Toc> const toc_;
147 std::stack<frame> stack_;
152 class TocBuilderStore
155 TocBuilderStore() {};
157 shared_ptr<TocBuilder> get(std::string const & type, shared_ptr<Toc> toc);
159 void clear() { map_.clear(); };
161 typedef std::map<std::string, shared_ptr<TocBuilder>> map_t;
172 static Toc::const_iterator findItem(Toc const & toc,
173 DocIterator const & dit);
174 /// Look for a TocItem given its depth and string.
175 /// \return The first matching item.
176 /// \retval end() if no item was found.
177 static Toc::iterator findItem(Toc & toc, int depth, docstring const & str);
179 TocBackend(Buffer const * buffer) : buffer_(buffer) {}
181 void setBuffer(Buffer const * buffer) { buffer_ = buffer; }
183 void update(bool output_active, UpdateType utype);
184 /// \return true if the item was updated.
185 bool updateItem(DocIterator const & pit);
187 TocList const & tocs() const { return tocs_; }
189 shared_ptr<Toc const> toc(std::string const & type) const;
190 shared_ptr<Toc> toc(std::string const & type);
192 shared_ptr<TocBuilder> builder(std::string const & type);
193 /// Return the first Toc Item before the cursor
194 Toc::const_iterator item(
195 std::string const & type, ///< Type of Toc.
196 DocIterator const & dit ///< The cursor location in the document.
200 void writePlaintextTocList(std::string const & type,
201 odocstringstream & os, size_t max_length) const;
203 docstring outlinerName(std::string const & type) const;
209 TocBuilderStore builders_;
211 Buffer const * buffer_;
217 #endif // TOC_BACKEND_H