]> git.lyx.org Git - lyx.git/blob - src/mathed/ref_inset.C
Strip out redundant #includes
[lyx.git] / src / mathed / ref_inset.C
1 /**
2  * \file ref_inset.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "ref_inset.h"
14 #include "math_factory.h"
15
16 #include "BufferView.h"
17 #include "debug.h"
18 #include "funcrequest.h"
19 #include "math_support.h"
20 #include "gettext.h"
21 #include "LaTeXFeatures.h"
22
23 #include "frontends/LyXView.h"
24 #include "frontends/Dialogs.h"
25
26
27 using std::auto_ptr;
28 using std::endl;
29
30
31 RefInset::RefInset()
32         : CommandInset("ref")
33 {}
34
35
36 RefInset::RefInset(string const & data)
37         : CommandInset(data)
38 {}
39
40
41 auto_ptr<InsetBase> RefInset::clone() const
42 {
43         return auto_ptr<InsetBase>(new RefInset(*this));
44 }
45
46
47 void RefInset::infoize(std::ostream & os) const
48 {
49         os << "Ref: " << cell(0);
50 }
51
52
53 dispatch_result
54 RefInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
55 {
56         switch (cmd.action) {
57                 case LFUN_MOUSE_RELEASE:
58                         if (cmd.button() == mouse_button::button3) {
59                                 lyxerr << "trying to goto ref" << cell(0) << endl;
60                                 cmd.view()->dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0))));
61                                 return DISPATCHED;
62                         }
63                         if (cmd.button() == mouse_button::button1) {
64                                 // Eventually trigger dialog with button 3
65                                 // not 1
66                                 string const data = createDialogStr("ref");
67                                 cmd.view()->owner()->getDialogs().
68                                         show("ref", data, this);
69                                 return DISPATCHED;
70                         }
71                         break;
72                 case LFUN_MOUSE_PRESS:
73                 case LFUN_MOUSE_MOTION:
74                         // eat other mouse commands
75                         return DISPATCHED;
76                 default:
77                         return CommandInset::dispatch(cmd, idx, pos);
78         }
79         // not our business
80         return UNDISPATCHED;
81 }
82
83
84 string const RefInset::screenLabel() const
85 {
86         string str;
87         for (int i = 0; !types[i].latex_name.empty(); ++i)
88                 if (commandname() == types[i].latex_name) {
89                         str = _(types[i].short_gui_name);
90                         break;
91                 }
92         str += asString(cell(0));
93
94         //if (/* !isLatex && */ !cell(0).empty()) {
95         //      str += "||";
96         //      str += asString(cell(1));
97         //}
98         return str;
99 }
100
101
102 void RefInset::validate(LaTeXFeatures & features) const
103 {
104         if (commandname() == "vref" || commandname() == "vpageref")
105                 features.require("varioref");
106         else if (commandname() == "prettyref")
107                 features.require("prettyref");
108 }
109
110
111 int RefInset::ascii(std::ostream & os, int) const
112 {
113         os << '[' << asString(cell(0)) << ']';
114         return 0;
115 }
116
117
118 int RefInset::linuxdoc(std::ostream & os) const
119 {
120         os << "<ref id=\"" << asString(cell(0))
121            << "\" name=\"" << asString(cell(1)) << "\" >";
122         return 0;
123 }
124
125
126 int RefInset::docbook(std::ostream & os, bool) const
127 {
128         if (cell(1).empty()) {
129                 os << "<xref linkend=\"" << asString(cell(0)) << "\">";
130         } else {
131                 os << "<link linkend=\"" << asString(cell(0))
132                    << "\">" << asString(cell(1)) << "</link>";
133         }
134
135         return 0;
136 }
137
138
139 dispatch_result RefInset::localDispatch(FuncRequest const & cmd)
140 {
141         if (cmd.action != LFUN_INSET_MODIFY || cmd.getArg(0) != "ref")
142                 return UNDISPATCHED;
143
144         MathArray ar;
145         if (!createMathInset_fromDialogStr(cmd.argument, ar))
146                 return UNDISPATCHED;
147
148         *this = *ar[0].nucleus()->asRefInset();
149 //      if (cmd.view())
150 //                 // This does not compile because updateInset expects
151 //                 // an Inset* and 'this' isn't.
152 //              cmd.view()->updateInset(this);
153         return DISPATCHED;
154 }
155
156
157 RefInset::ref_type_info RefInset::types[] = {
158         { "ref",       N_("Standard"),              N_("Ref: ")},
159         { "eqref",     N_("Equation"),              N_("EqRef: ")},
160         { "pageref",   N_("Page Number"),           N_("Page: ")},
161         { "vpageref",  N_("Textual Page Number"),   N_("TextPage: ")},
162         { "vref",      N_("Standard+Textual Page"), N_("Ref+Text: ")},
163         { "prettyref", N_("PrettyRef"),             N_("PrettyRef: ")},
164         { "", "", "" }
165 };