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