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