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"
26 #include "frontends/LyXView.h"
28 #include "insets/insetfloat.h"
29 #include "insets/insetoptarg.h"
30 #include "insets/insetwrap.h"
32 #include "support/convert.h"
50 typedef map<Buffer const *, lyx::TocBackend> TocMap;
51 static TocMap toc_backend_;
53 ///////////////////////////////////////////////////////////////////////////
54 // Interface to toc_backend_
56 void updateToc(Buffer const & buf)
58 TocMap::iterator it = toc_backend_.find(&buf);
59 if (it == toc_backend_.end()) {
60 pair<TocMap::iterator, bool> result
61 = toc_backend_.insert(make_pair(&buf, TocBackend(&buf)));
72 TocList const & getTocList(Buffer const & buf)
74 return toc_backend_[&buf].tocs();
78 Toc const & getToc(Buffer const & buf, std::string const & type)
80 return toc_backend_[&buf].toc(type);
84 TocIterator const getCurrentTocItem(Buffer const & buf, LCursor const & cur,
85 std::string const & type)
87 return toc_backend_[&buf].item(type, ParConstIterator(cur));
91 vector<string> const & getTypes(Buffer const & buf)
93 return toc_backend_[&buf].types();
97 void asciiTocList(string const & type, Buffer const & buf, ostream & os)
99 toc_backend_[&buf].asciiTocList(type, os);
102 ///////////////////////////////////////////////////////////////////////////
105 string const getType(string const & cmdName)
108 if (cmdName == "tableofcontents")
115 string const getGuiName(string const & type, Buffer const & buffer)
117 FloatList const & floats =
118 buffer.params().getLyXTextClass().floats();
119 if (floats.typeExist(type))
120 return floats.getType(type).name();
126 void outline(OutlineOp mode, Buffer * buf, pit_type & pit)
128 ParagraphList & pars = buf->text().paragraphs();
129 ParagraphList::iterator bgn = pars.begin();
130 ParagraphList::iterator s = boost::next(bgn, pit);
131 ParagraphList::iterator p = s;
132 ParagraphList::iterator end = pars.end();
134 LyXTextClass::const_iterator lit =
135 buf->params().getLyXTextClass().begin();
136 LyXTextClass::const_iterator const lend =
137 buf->params().getLyXTextClass().end();
139 int const thistoclevel = s->layout()->toclevel;
145 for (; p != end; ++p) {
146 toclevel = p->layout()->toclevel;
147 if (toclevel != LyXLayout::NOT_IN_TOC
148 && toclevel <= thistoclevel) {
152 ParagraphList::iterator q = s;
157 for (; q != bgn; --q) {
158 toclevel = q->layout()->toclevel;
159 if (toclevel != LyXLayout::NOT_IN_TOC
160 && toclevel <= thistoclevel) {
164 pit_type const newpit = std::distance(pars.begin(), q);
165 pit_type const len = std::distance(s, p);
167 pars.insert(q, s, p);
168 s = boost::next(pars.begin(), pit);
169 ParagraphList::iterator t = boost::next(s, len);
177 for (; p != end; ++p) {
178 toclevel = p->layout()->toclevel;
179 if (toclevel != LyXLayout::NOT_IN_TOC
180 && toclevel <= thistoclevel) {
184 ParagraphList::iterator q = p;
189 for (; q != end; ++q) {
190 toclevel = q->layout()->toclevel;
191 if (toclevel != LyXLayout::NOT_IN_TOC
192 && toclevel <= thistoclevel) {
196 pit_type const newpit = std::distance(pars.begin(), q);
197 pit_type const len = std::distance(s, p);
198 pars.insert(q, s, p);
199 s = boost::next(pars.begin(), pit);
200 ParagraphList::iterator t = boost::next(s, len);
206 for (; lit != lend; ++lit) {
207 if ((*lit)->toclevel == thistoclevel + 1) {
214 for (; lit != lend; ++lit) {
215 if ((*lit)->toclevel == thistoclevel - 1) {