]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathRef.C
Support lgathered and rgathered math environments
[lyx.git] / src / mathed / InsetMathRef.C
1 /**
2  * \file InsetMathRef.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 "InsetMathRef.h"
14
15 #include "BufferView.h"
16 #include "LaTeXFeatures.h"
17 #include "buffer.h"
18 #include "cursor.h"
19 #include "debug.h"
20 #include "funcrequest.h"
21 #include "FuncStatus.h"
22 #include "gettext.h"
23 #include "MathData.h"
24 #include "MathFactory.h"
25 #include "MathSupport.h"
26 #include "outputparams.h"
27 #include "sgml.h"
28
29 using std::string;
30 using std::auto_ptr;
31 using std::endl;
32
33
34 RefInset::RefInset()
35         : CommandInset("ref")
36 {}
37
38
39 RefInset::RefInset(string const & data)
40         : CommandInset(data)
41 {}
42
43
44 auto_ptr<InsetBase> RefInset::doClone() const
45 {
46         return auto_ptr<InsetBase>(new RefInset(*this));
47 }
48
49
50 void RefInset::infoize(std::ostream & os) const
51 {
52         os << "Ref: " << cell(0);
53 }
54
55
56 void RefInset::doDispatch(LCursor & cur, FuncRequest & cmd)
57 {
58         switch (cmd.action) {
59         case LFUN_INSET_MODIFY:
60                 if (cmd.getArg(0) == "ref") {
61                         MathArray ar;
62                         if (createInsetMath_fromDialogStr(lyx::to_utf8(cmd.argument()), ar)) {
63                                 *this = *ar[0].nucleus()->asRefInset();
64                                 break;
65                         }
66                 }
67                 cur.undispatched();
68                 break;
69
70         case LFUN_INSET_DIALOG_UPDATE: {
71                 string const data = createDialogStr("ref");
72                 cur.bv().updateDialog("ref", data);
73                 break;
74         }
75
76         case LFUN_MOUSE_RELEASE:
77                 if (cmd.button() == mouse_button::button3) {
78                         lyxerr << "trying to goto ref '" << asString(cell(0)) << "'" << endl;
79                         cur.bv().dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
80                         break;
81                 }
82                 if (cmd.button() == mouse_button::button1) {
83                         // Eventually trigger dialog with button 3, not 1
84                         string const data = createDialogStr("ref");
85                         cur.bv().showInsetDialog("ref", data, this);
86                         break;
87                 }
88                 cur.undispatched();
89                 break;
90
91         case LFUN_MOUSE_PRESS:
92         case LFUN_MOUSE_MOTION:
93                 // eat other mouse commands
94                 break;
95
96         default:
97                 CommandInset::doDispatch(cur, cmd);
98                 break;
99         }
100 }
101
102
103 bool RefInset::getStatus(LCursor & cur, FuncRequest const & cmd,
104                          FuncStatus & status) const
105 {
106         switch (cmd.action) {
107         // we handle these
108         case LFUN_INSET_MODIFY:
109         case LFUN_INSET_DIALOG_UPDATE:
110         case LFUN_MOUSE_RELEASE:
111         case LFUN_MOUSE_PRESS:
112         case LFUN_MOUSE_MOTION:
113                 status.enabled(true);
114                 return true;
115         default:
116                 return CommandInset::getStatus(cur, cmd, status);
117         }
118 }
119
120
121 string const RefInset::screenLabel() const
122 {
123         string str;
124         for (int i = 0; !types[i].latex_name.empty(); ++i)
125                 if (commandname() == types[i].latex_name) {
126                         // FIXME UNICODE
127                         str = lyx::to_utf8(_(types[i].short_gui_name));
128                         break;
129                 }
130         str += asString(cell(0));
131
132         //if (/* !isLatex && */ !cell(0).empty()) {
133         //      str += "||";
134         //      str += asString(cell(1));
135         //}
136         return str;
137 }
138
139
140 void RefInset::validate(LaTeXFeatures & features) const
141 {
142         if (commandname() == "vref" || commandname() == "vpageref")
143                 features.require("varioref");
144         else if (commandname() == "prettyref")
145                 features.require("prettyref");
146 }
147
148
149 int RefInset::plaintext(std::ostream & os, OutputParams const &) const
150 {
151         os << '[' << asString(cell(0)) << ']';
152         return 0;
153 }
154
155
156 int RefInset::docbook(Buffer const & buf, std::ostream & os, OutputParams const & runparams) const
157 {
158         if (cell(1).empty()) {
159                 os << "<xref linkend=\"" << sgml::cleanID(buf, runparams, asString(cell(0)));
160                 if (runparams.flavor == OutputParams::XML)
161                         os << "\"/>";
162                 else
163                         os << "\">";
164         } else {
165                 os << "<link linkend=\"" << sgml::cleanID(buf, runparams, asString(cell(0)))
166                    << "\">" << asString(cell(1)) << "</link>";
167         }
168
169         return 0;
170 }
171
172
173 RefInset::ref_type_info RefInset::types[] = {
174         { "ref",       N_("Standard"),              N_("Ref: ")},
175         { "eqref",     N_("Equation"),              N_("EqRef: ")},
176         { "pageref",   N_("Page Number"),           N_("Page: ")},
177         { "vpageref",  N_("Textual Page Number"),   N_("TextPage: ")},
178         { "vref",      N_("Standard+Textual Page"), N_("Ref+Text: ")},
179         { "prettyref", N_("PrettyRef"),             N_("PrettyRef: ")},
180         { "", "", "" }
181 };