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 "frontends/LyXView.h"
29 #include "insets/insetfloat.h"
30 #include "insets/insetoptarg.h"
31 #include "insets/insetwrap.h"
33 #include "support/convert.h"
51 typedef map<Buffer const *, lyx::TocBackend> TocMap;
52 static TocMap toc_backend_;
54 ///////////////////////////////////////////////////////////////////////////
55 // Interface to toc_backend_
57 void updateToc(Buffer const & buf)
59 TocMap::iterator it = toc_backend_.find(&buf);
60 if (it == toc_backend_.end()) {
61 pair<TocMap::iterator, bool> result
62 = toc_backend_.insert(make_pair(&buf, TocBackend(&buf)));
73 TocList const & getTocList(Buffer const & buf)
75 return toc_backend_[&buf].tocs();
79 Toc const & getToc(Buffer const & buf, std::string const & type)
81 return toc_backend_[&buf].toc(type);
85 TocIterator const getCurrentTocItem(Buffer const & buf, LCursor const & cur,
86 std::string const & type)
88 return toc_backend_[&buf].item(type, ParConstIterator(cur));
92 vector<string> const & getTypes(Buffer const & buf)
94 return toc_backend_[&buf].types();
98 void asciiTocList(string const & type, Buffer const & buf, ostream & os)
100 toc_backend_[&buf].asciiTocList(type, os);
103 ///////////////////////////////////////////////////////////////////////////
106 string const getType(string const & cmdName)
109 if (cmdName == "tableofcontents")
116 string const getGuiName(string const & type, Buffer const & buffer)
118 FloatList const & floats =
119 buffer.params().getLyXTextClass().floats();
120 if (floats.typeExist(type))
121 return floats.getType(type).name();
127 void outline(OutlineOp mode, LCursor & cur)
130 Buffer * buf = & cur.buffer();
131 pit_type & pit = cur.pit();
132 ParagraphList & pars = buf->text().paragraphs();
133 ParagraphList::iterator bgn = pars.begin();
134 ParagraphList::iterator s = boost::next(bgn, pit);
135 ParagraphList::iterator p = s;
136 ParagraphList::iterator end = pars.end();
138 LyXTextClass::const_iterator lit =
139 buf->params().getLyXTextClass().begin();
140 LyXTextClass::const_iterator const lend =
141 buf->params().getLyXTextClass().end();
143 int const thistoclevel = s->layout()->toclevel;
149 for (; p != end; ++p) {
150 toclevel = p->layout()->toclevel;
151 if (toclevel != LyXLayout::NOT_IN_TOC
152 && toclevel <= thistoclevel) {
156 ParagraphList::iterator q = s;
161 for (; q != bgn; --q) {
162 toclevel = q->layout()->toclevel;
163 if (toclevel != LyXLayout::NOT_IN_TOC
164 && toclevel <= thistoclevel) {
168 pit_type const newpit = std::distance(pars.begin(), q);
169 pit_type const len = std::distance(s, p);
171 pars.insert(q, s, p);
172 s = boost::next(pars.begin(), pit);
173 ParagraphList::iterator t = boost::next(s, len);
181 for (; p != end; ++p) {
182 toclevel = p->layout()->toclevel;
183 if (toclevel != LyXLayout::NOT_IN_TOC
184 && toclevel <= thistoclevel) {
188 ParagraphList::iterator q = p;
193 for (; q != end; ++q) {
194 toclevel = q->layout()->toclevel;
195 if (toclevel != LyXLayout::NOT_IN_TOC
196 && toclevel <= thistoclevel) {
200 pit_type const newpit = std::distance(pars.begin(), q);
201 pit_type const len = std::distance(s, p);
202 pars.insert(q, s, p);
203 s = boost::next(pars.begin(), pit);
204 ParagraphList::iterator t = boost::next(s, len);
210 for (; lit != lend; ++lit) {
211 if ((*lit)->toclevel == thistoclevel + 1 &&
212 s->layout()->labeltype == (*lit)->labeltype) {
219 for (; lit != lend; ++lit) {
220 if ((*lit)->toclevel == thistoclevel - 1 &&
221 s->layout()->labeltype == (*lit)->labeltype) {