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"
33 /* FIXME: toc types are currently identified by strings. It cannot be converted
34 * into an enum because of the user-configurable indexing categories and
35 * the user-definable float types provided by layout files.
37 * I leave this for documentation purposes for the moment.
40 TABLE_OF_CONTENTS,//"tableofcontents"
50 MARGINAL_NOTE,//"marginalnote"
51 INDEX,//"index", "index:<user-str>" (from interface)
54 FLOAT,//"figure", "table", "algorithm", user-defined (from layout?)
55 MATH_MACRO,//"math-macro"
57 SENSELESS,//"senseless"
67 friend class TocBackend;
68 friend class TocBuilder;
71 /// Default constructor for STL containers.
72 TocItem() : dit_(0), depth_(0), output_(false) {}
74 TocItem(DocIterator const & dit,
78 docstring const & t = docstring(),
79 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(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 shared_ptr<Toc> const toc_;
145 std::stack<frame> stack_;
150 class TocBuilderStore
153 TocBuilderStore() {};
155 shared_ptr<TocBuilder> get(std::string const & type, shared_ptr<Toc> toc);
157 void clear() { map_.clear(); };
159 typedef std::map<std::string, shared_ptr<TocBuilder> > map_t;
170 static Toc::const_iterator findItem(Toc const & toc,
171 DocIterator const & dit);
172 /// Look for a TocItem given its depth and string.
173 /// \return The first matching item.
174 /// \retval end() if no item was found.
175 static Toc::iterator findItem(Toc & toc, int depth, docstring const & str);
177 TocBackend(Buffer const * buffer) : buffer_(buffer) {}
179 void setBuffer(Buffer const * buffer) { buffer_ = buffer; }
181 void update(bool output_active, UpdateType utype);
182 /// \return true if the item was updated.
183 bool updateItem(DocIterator const & pit);
185 TocList const & tocs() const { return tocs_; }
187 shared_ptr<Toc const> toc(std::string const & type) const;
188 shared_ptr<Toc> toc(std::string const & type);
190 shared_ptr<TocBuilder> builder(std::string const & type);
191 /// Return the first Toc Item before the cursor
192 Toc::const_iterator item(
193 std::string const & type, ///< Type of Toc.
194 DocIterator const & dit ///< The cursor location in the document.
198 void writePlaintextTocList(std::string const & type,
199 odocstringstream & os, size_t max_length) const;
201 docstring outlinerName(std::string const & type) const;
207 TocBuilderStore builders_;
209 Buffer const * buffer_;
215 #endif // TOC_BACKEND_H