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"
20 #include "support/shared_ptr.h"
21 #include "support/strfwd.h"
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 SENSELESS,//"senseless"
68 friend class TocBackend;
71 /// Default constructor for STL containers.
72 TocItem() : dit_(0), depth_(0), output_(false) {}
74 TocItem(DocIterator const & dit,
78 docstring const & t = docstring()
85 int depth() const { return depth_; }
87 docstring const & str() const { return str_; }
89 void str(docstring const & s) { str_ = s; }
91 docstring const & tooltip() const;
93 docstring const asString() const;
95 DocIterator const & dit() const { return dit_; }
97 bool isOutput() const { return output_; }
99 /// the action corresponding to the goTo above
100 FuncRequest action() const;
103 /// Current position of item.
109 /// The tooltip string
111 /// Is this item in a note, inactive branch, etc?
117 class Toc : public std::vector<TocItem>
120 typedef std::vector<TocItem>::const_iterator const_iterator;
121 typedef std::vector<TocItem>::iterator iterator;
122 const_iterator item(DocIterator const & dit) const;
123 /// Look for a TocItem given its depth and string.
124 /// \return The first matching item.
125 /// \retval end() if no item was found.
126 iterator item(int depth, docstring const & str);
129 typedef Toc::const_iterator TocIterator;
132 /// Caption-enabled TOC builders
136 TocBuilder(shared_ptr<Toc> const toc);
137 /// When entering a float
138 void pushItem(DocIterator const & dit, docstring const & s,
139 bool output_active, bool is_captioned = false);
140 /// When encountering a caption
141 void captionItem(DocIterator const & dit, docstring const & s,
143 /// When exiting a float
149 Toc::size_type const pos;
153 shared_ptr<Toc> const toc_;
155 std::stack<frame> stack_;
160 /// A class and no typedef because we want to forward declare it.
161 class TocList : public std::map<std::string, shared_ptr<Toc> >
164 // this can create null pointers
165 using std::map<std::string, shared_ptr<Toc> >::operator[];
170 class TocBuilderStore
173 TocBuilderStore() {};
175 shared_ptr<TocBuilder> get(std::string const & type, shared_ptr<Toc> toc);
177 void clear() { map_.clear(); };
179 typedef std::map<std::string, shared_ptr<TocBuilder> > map_t;
191 TocBackend(Buffer const * buffer) : buffer_(buffer) {}
193 void setBuffer(Buffer const * buffer) { buffer_ = buffer; }
195 void update(bool output_active);
196 /// \return true if the item was updated.
197 bool updateItem(DocIterator const & pit);
199 TocList const & tocs() const { return tocs_; }
201 shared_ptr<Toc const> toc(std::string const & type) const;
202 shared_ptr<Toc> toc(std::string const & type);
204 shared_ptr<TocBuilder> builder(std::string const & type);
205 /// Return the first Toc Item before the cursor
207 std::string const & type, ///< Type of Toc.
208 DocIterator const & dit ///< The cursor location in the document.
212 void writePlaintextTocList(std::string const & type,
213 odocstringstream & os, size_t max_length) const;
219 TocBuilderStore builders_;
221 Buffer const * buffer_;
227 #endif // TOC_BACKEND_H