3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Jean-Marc Lasgouttes
7 * \author Angus Leeming
8 * \author Abdelrazak Younes
10 * Full author contact details are available in file CREDITS.
18 #include "bufferparams.h"
19 #include "FloatList.h"
20 #include "funcrequest.h"
21 #include "LyXAction.h"
22 #include "paragraph.h"
27 #include "insets/insetfloat.h"
28 #include "insets/insetoptarg.h"
29 #include "insets/insetwrap.h"
31 #include "support/convert.h"
49 typedef map<Buffer const *, lyx::TocBackend> TocMap;
50 static TocMap toc_backend_;
52 ///////////////////////////////////////////////////////////////////////////
53 // Interface to toc_backend_
55 void updateToc(Buffer const & buf)
57 TocMap::iterator it = toc_backend_.find(&buf);
58 if (it == toc_backend_.end()) {
59 pair<TocMap::iterator, bool> result
60 = toc_backend_.insert(make_pair(&buf, TocBackend(&buf)));
71 TocList const & getTocList(Buffer const & buf)
73 return toc_backend_[&buf].tocs();
77 Toc const & getToc(Buffer const & buf, std::string const & type)
79 return toc_backend_[&buf].toc(type);
83 TocIterator const getCurrentTocItem(Buffer const & buf, LCursor const & cur,
84 std::string const & type)
86 return toc_backend_[&buf].item(type, ParConstIterator(cur));
90 vector<string> const & getTypes(Buffer const & buf)
92 return toc_backend_[&buf].types();
96 void asciiTocList(string const & type, Buffer const & buf, ostream & os)
98 toc_backend_[&buf].asciiTocList(type, os);
101 ///////////////////////////////////////////////////////////////////////////
104 string const getType(string const & cmdName)
107 if (cmdName == "tableofcontents")
114 string const getGuiName(string const & type, Buffer const & buffer)
116 FloatList const & floats =
117 buffer.params().getLyXTextClass().floats();
118 if (floats.typeExist(type))
119 return floats.getType(type).name();
125 void outline(OutlineOp mode, LCursor & cur)
128 Buffer * buf = & cur.buffer();
129 pit_type & pit = cur.pit();
130 ParagraphList & pars = buf->text().paragraphs();
131 ParagraphList::iterator bgn = pars.begin();
132 ParagraphList::iterator s = boost::next(bgn, pit);
133 ParagraphList::iterator p = s;
134 ParagraphList::iterator end = pars.end();
136 LyXTextClass::const_iterator lit =
137 buf->params().getLyXTextClass().begin();
138 LyXTextClass::const_iterator const lend =
139 buf->params().getLyXTextClass().end();
141 int const thistoclevel = s->layout()->toclevel;
147 for (; p != end; ++p) {
148 toclevel = p->layout()->toclevel;
149 if (toclevel != LyXLayout::NOT_IN_TOC
150 && toclevel <= thistoclevel) {
154 ParagraphList::iterator q = s;
159 for (; q != bgn; --q) {
160 toclevel = q->layout()->toclevel;
161 if (toclevel != LyXLayout::NOT_IN_TOC
162 && toclevel <= thistoclevel) {
166 pit_type const newpit = std::distance(pars.begin(), q);
167 pit_type const len = std::distance(s, p);
169 pars.insert(q, s, p);
170 s = boost::next(pars.begin(), pit);
171 ParagraphList::iterator t = boost::next(s, len);
179 for (; p != end; ++p) {
180 toclevel = p->layout()->toclevel;
181 if (toclevel != LyXLayout::NOT_IN_TOC
182 && toclevel <= thistoclevel) {
186 ParagraphList::iterator q = p;
191 for (; q != end; ++q) {
192 toclevel = q->layout()->toclevel;
193 if (toclevel != LyXLayout::NOT_IN_TOC
194 && toclevel <= thistoclevel) {
198 pit_type const newpit = std::distance(pars.begin(), q);
199 pit_type const len = std::distance(s, p);
200 pars.insert(q, s, p);
201 s = boost::next(pars.begin(), pit);
202 ParagraphList::iterator t = boost::next(s, len);
208 for (; lit != lend; ++lit) {
209 if ((*lit)->toclevel == thistoclevel + 1 &&
210 s->layout()->labeltype == (*lit)->labeltype) {
217 for (; lit != lend; ++lit) {
218 if ((*lit)->toclevel == thistoclevel - 1 &&
219 s->layout()->labeltype == (*lit)->labeltype) {