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