- if (!buf)
- return toclist;
- Paragraph * par = buf->paragraph;
-
- LyXTextClass const & textclass = buf->params.getLyXTextClass();
-
- while (par) {
-#ifdef WITH_WARNINGS
-#warning bogus type (Lgb)
-#endif
- char const labeltype = par->layout()->labeltype;
-
- if (labeltype >= LABEL_COUNTER_CHAPTER
- && labeltype <= LABEL_COUNTER_CHAPTER + buf->params.tocdepth) {
- // insert this into the table of contents
- const int depth = max(0, labeltype - textclass.maxcounter());
- TocItem const item(par, depth,
- par->asString(buf, true));
+
+ BufferParams const & bufparams = buf.params();
+
+ ParConstIterator pit = buf.par_iterator_begin();
+ ParConstIterator end = buf.par_iterator_end();
+ for (; pit != end; ++pit) {
+
+ int const toclevel = pit->layout()->toclevel;
+ if (toclevel > 0 && toclevel <= bufparams.tocdepth) {
+ // insert this into the table of contents
+ TocItem const item(pit->id(), toclevel - 1, pit->asString(buf, true));