]> git.lyx.org Git - lyx.git/blob - src/insets/insettoc.C
f68649a009befbb9f9b00624e686dc66ad1a7ef0
[lyx.git] / src / insets / insettoc.C
1 /**
2  * \file insettoc.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10 #include <config.h>
11
12 #include "insettoc.h"
13
14 #include "BufferView.h"
15 #include "debug.h"
16 #include "funcrequest.h"
17 #include "gettext.h"
18 #include "metricsinfo.h"
19 #include "toc.h"
20 #include "frontends/LyXView.h"
21 #include "frontends/Dialogs.h"
22
23
24 using std::vector;
25 using std::ostream;
26
27
28 InsetTOC::InsetTOC(InsetCommandParams const & p)
29         : InsetCommand(p)
30 {}
31
32
33 InsetTOC::~InsetTOC()
34 {
35         InsetCommandMailer mailer("toc", *this);
36         mailer.hideDialog();
37 }
38
39
40 string const InsetTOC::getScreenLabel(Buffer const &) const
41 {
42         string const cmdname(getCmdName());
43
44         if (cmdname == "tableofcontents")
45                 return _("Table of Contents");
46         return _("Unknown toc list");
47 }
48
49
50 InsetOld::Code InsetTOC::lyxCode() const
51 {
52         string const cmdname(getCmdName());
53         if (cmdname == "tableofcontents")
54                 return InsetOld::TOC_CODE;
55         return InsetOld::NO_CODE;
56 }
57
58
59 void InsetTOC::metrics(MetricsInfo & mi, Dimension & dim) const
60 {
61         InsetCommand::metrics(mi, dim);
62         center_indent_ = (mi.base.textwidth - dim.wid) / 2;
63         dim.wid = mi.base.textwidth;
64         dim_ = dim;
65 }
66
67
68 void InsetTOC::draw(PainterInfo & pi, int x, int y) const
69 {
70         InsetCommand::draw(pi, x + center_indent_, y);
71 }
72
73
74 dispatch_result InsetTOC::localDispatch(FuncRequest const & cmd)
75 {
76         switch (cmd.action) {
77         case LFUN_INSET_EDIT:
78                 InsetCommandMailer("toc", *this).showDialog(cmd.view());
79                 return DISPATCHED;
80         default:
81                 return InsetCommand::localDispatch(cmd);
82         }
83 }
84
85
86 int InsetTOC::ascii(Buffer const & buffer, ostream & os, int) const
87 {
88         os << getScreenLabel(buffer) << "\n\n";
89
90         lyx::toc::asciiTocList(lyx::toc::getType(getCmdName()), buffer, os);
91
92         os << "\n";
93         return 0;
94 }
95
96
97 int InsetTOC::linuxdoc(Buffer const &, ostream & os) const
98 {
99         if (getCmdName() == "tableofcontents")
100                 os << "<toc>";
101         return 0;
102 }
103
104
105 int InsetTOC::docbook(Buffer const &, ostream & os, bool) const
106 {
107         if (getCmdName() == "tableofcontents")
108                 os << "<toc></toc>";
109         return 0;
110 }