]> git.lyx.org Git - lyx.git/blob - src/insets/insettoc.C
74273ce85eed42cdef56655633b0493fe5a2b42c
[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 "BufferView.h"
15 #include "debug.h"
16 #include "funcrequest.h"
17 #include "gettext.h"
18 #include "metricsinfo.h"
19 #include "toc.h"
20 #include "frontends/LyXView.h"
21 #include "frontends/Dialogs.h"
22
23
24 using std::vector;
25 using std::ostream;
26
27
28 InsetTOC::InsetTOC(InsetCommandParams const & p)
29         : InsetCommand(p)
30 {}
31
32
33 InsetTOC::~InsetTOC()
34 {
35         InsetCommandMailer mailer("toc", *this);
36         mailer.hideDialog();
37 }
38
39
40 string const InsetTOC::getScreenLabel(Buffer const &) const
41 {
42         string const cmdname(getCmdName());
43
44         if (cmdname == "tableofcontents")
45                 return _("Table of Contents");
46         return _("Unknown toc list");
47 }
48
49
50 InsetOld::Code InsetTOC::lyxCode() const
51 {
52         string const cmdname(getCmdName());
53         if (cmdname == "tableofcontents")
54                 return InsetOld::TOC_CODE;
55         return InsetOld::NO_CODE;
56 }
57
58
59 void InsetTOC::metrics(MetricsInfo & mi, Dimension & dim) const
60 {
61         InsetCommand::metrics(mi, dim);
62         int center_indent = (mi.base.textwidth - dim.wid) / 2;
63         Box b(center_indent, center_indent + dim.wid, -dim.asc, dim.des);
64         button().setBox(b);
65
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, x + button().box().x1, y);
74 }
75
76
77 dispatch_result InsetTOC::localDispatch(FuncRequest const & cmd)
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::localDispatch(cmd);
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 }