]> git.lyx.org Git - lyx.git/blob - src/insets/insettoc.C
666abdbc9db4cd3107f4f7762751104f935098ba
[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 "funcrequest.h"
15 #include "gettext.h"
16 #include "metricsinfo.h"
17 #include "toc.h"
18
19 using std::ostream;
20 using std::vector;
21
22
23 InsetTOC::InsetTOC(InsetCommandParams const & p)
24         : InsetCommand(p)
25 {}
26
27
28 InsetTOC::~InsetTOC()
29 {
30         InsetCommandMailer mailer("toc", *this);
31         mailer.hideDialog();
32 }
33
34
35 string const InsetTOC::getScreenLabel(Buffer const &) const
36 {
37         string const cmdname(getCmdName());
38
39         if (cmdname == "tableofcontents")
40                 return _("Table of Contents");
41         return _("Unknown toc list");
42 }
43
44
45 InsetOld::Code InsetTOC::lyxCode() const
46 {
47         string const cmdname(getCmdName());
48         if (cmdname == "tableofcontents")
49                 return InsetOld::TOC_CODE;
50         return InsetOld::NO_CODE;
51 }
52
53
54 void InsetTOC::metrics(MetricsInfo & mi, Dimension & dim) const
55 {
56         InsetCommand::metrics(mi, dim);
57         int center_indent = (mi.base.textwidth - dim.wid) / 2;
58         Box b(center_indent, center_indent + dim.wid, -dim.asc, dim.des);
59         button().setBox(b);
60
61         dim.wid = mi.base.textwidth;
62         dim_ = dim;
63 }
64
65
66 void InsetTOC::draw(PainterInfo & pi, int x, int y) const
67 {
68         InsetCommand::draw(pi, x + button().box().x1, y);
69 }
70
71
72 dispatch_result InsetTOC::localDispatch(FuncRequest const & cmd)
73 {
74         switch (cmd.action) {
75         case LFUN_MOUSE_RELEASE:
76                 if (button().box().contains(cmd.x, cmd.y))
77                         InsetCommandMailer("toc", *this).showDialog(cmd.view());
78                 return DISPATCHED;
79
80         case LFUN_INSET_DIALOG_SHOW:
81                 InsetCommandMailer("toc", *this).showDialog(cmd.view());
82                 return DISPATCHED;
83
84         default:
85                 return InsetCommand::localDispatch(cmd);
86         }
87 }
88
89
90 int InsetTOC::ascii(Buffer const & buffer, ostream & os, int) const
91 {
92         os << getScreenLabel(buffer) << "\n\n";
93
94         lyx::toc::asciiTocList(lyx::toc::getType(getCmdName()), buffer, os);
95
96         os << "\n";
97         return 0;
98 }
99
100
101 int InsetTOC::linuxdoc(Buffer const &, ostream & os) const
102 {
103         if (getCmdName() == "tableofcontents")
104                 os << "<toc>";
105         return 0;
106 }
107
108
109 int InsetTOC::docbook(Buffer const &, ostream & os, bool) const
110 {
111         if (getCmdName() == "tableofcontents")
112                 os << "<toc></toc>";
113         return 0;
114 }