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