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