]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/ControlMath.C
Add a buffer_path arg to InsetGraphicsMailer's params2string, string2params.
[lyx.git] / src / frontends / controllers / ControlMath.C
index f9a3cf9edf61709ba1914a3c14f949ecd1bca3e5..ea5927f2c09eee3c9e6a7b401c91df9297be92e9 100644 (file)
@@ -1,13 +1,89 @@
 /**
  * \file ControlMath.C
- * Copyright 2001 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * \author Alejandro Aguilar Sierra
- * \author John Levon, moz@compsoc.man.ac.uk
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS
  */
 
+#include <config.h>
+
 #include "ControlMath.h"
+#include "Kernel.h"
+#include "debug.h"
+#include "funcrequest.h"
+
+#include "support/LAssert.h"
+#include "support/lyxalgo.h" // sorted
+#include "support/lstrings.h"
+#include "support/filetools.h"
+
+
+using namespace lyx::support;
+
+
+ControlMath::ControlMath(Dialog & dialog)
+       : Dialog::Controller(dialog)
+{}
+
+
+void ControlMath::dispatchFunc(kb_action action, string const & arg) const
+{
+       kernel().dispatch(FuncRequest(action, arg));
+}
+
+
+void ControlMath::dispatchInsert(string const & name) const
+{
+       dispatchFunc(LFUN_INSERT_MATH, '\\' + name);
+}
+
+
+void ControlMath::dispatchSubscript() const
+{
+       dispatchFunc(LFUN_SUBSCRIPT);
+}
+
+
+void ControlMath::dispatchSuperscript() const
+{
+       dispatchFunc(LFUN_SUPERSCRIPT);
+}
+
+
+void ControlMath::dispatchCubeRoot() const
+{
+       dispatchFunc(LFUN_INSERT_MATH, "\\root");
+       dispatchFunc(LFUN_SELFINSERT, "3");
+       dispatchFunc(LFUN_RIGHT);
+}
+
+
+void ControlMath::dispatchMatrix(string const & str) const
+{
+       dispatchFunc(LFUN_INSERT_MATRIX, str);
+}
+
+
+void ControlMath::dispatchDelim(string const & str) const
+{
+       dispatchFunc(LFUN_MATH_DELIM, str);
+}
+
+
+void ControlMath::dispatchToggleDisplay() const
+{
+       dispatchFunc(LFUN_MATH_DISPLAY);
+}
+
+
+void ControlMath::showDialog(string const & name) const
+{
+       dispatchFunc(LFUN_DIALOG_SHOW, name);
+}
+
 
 char const * function_names[] = {
        "arccos", "arcsin", "arctan", "arg", "bmod",
@@ -15,11 +91,28 @@ char const * function_names[] = {
        "det", "dim", "exp", "gcd", "hom", "inf", "ker",
        "lg", "lim", "liminf", "limsup", "ln", "log",
        "max", "min", "sec", "sin", "sinh", "sup",
-       "tan", "tanh", ""
+       "tan", "tanh", "Pr", ""
 };
 
 int const nr_function_names = sizeof(function_names) / sizeof(char const *) - 1;
 
+char const * latex_dots[] = {
+       "ldots", "cdots", "vdots", "ddots", ""
+};
+
+int const nr_latex_dots = sizeof(latex_dots) / sizeof(char const *) - 1;
+
+char const * latex_deco[] = {
+       "widehat", "widetilde", "overbrace", "overleftarrow", "overrightarrow",
+       "overline", "underbrace", "underline", "underleftarrow", "underrightarrow",
+       "underleftrightarrow", "overleftrightarrow",
+       "hat", "acute", "bar", "dot",
+       "check", "grave", "vec", "ddot",
+       "breve", "tilde", ""
+};
+
+int const nr_latex_deco = sizeof(latex_deco) / sizeof(char const *) - 1;
+
 char const * latex_arrow[] = {
        "downarrow", "leftarrow", "Downarrow", "Leftarrow",
        "hookleftarrow", "rightarrow", "uparrow", "Rightarrow", "Uparrow",
@@ -60,12 +153,6 @@ char const * latex_brel[] = {
 
 int const nr_latex_brel = sizeof(latex_brel) / sizeof(char const *);
 
-char const * latex_dots[] = {
-       "ldots", "cdots", "vdots", "ddots"
-};
-
-int const nr_latex_dots = sizeof(latex_dots) / sizeof(char const *);
-
 char const * latex_greek[] = {
        "Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi",
        "Sigma", "Upsilon", "Phi", "Psi", "Omega",
@@ -84,7 +171,7 @@ char const * latex_misc[] = {
        "angle", "top", "bot", "Vert", "neg",
        "flat", "natural", "sharp", "surd", "triangle",
        "diamondsuit", "heartsuit", "clubsuit", "spadesuit",
-       "textrm Å", "textrm Ø", "mathcircumflex", "_",
+       "textrm Å", "textrm Ø", "mathcircumflex", "_",
        "mathrm T",
        "mathbb N", "mathbb Z", "mathbb Q",
        "mathbb R", "mathbb C", "mathbb H",
@@ -144,7 +231,7 @@ char const * latex_ams_rel[] = {
        "lessdot", "lll", "lessgtr", "gtreqless", "gtreqqless", "eqcirc",
        "lesseqgtr", "lesseqqgtr", "doteqdot", "circeq", "triangleq", "thicksim",
        "risingdotseq", "fallingdotseq", "backsim", "thickapprox", "supseteqq", "Supset",
-       "backsimeq", "subseteqq", "Subset","sqsupset", "succcurlyeq", "curlyeqsucc",
+       "backsimeq", "subseteqq", "Subset", "sqsupset", "succcurlyeq", "curlyeqsucc",
        "sqsubset", "preccurlyeq", "curlyeqprec", "succsim", "succapprox", "vartriangleright",
        "precsim", "precapprox", "vartriangleleft", "trianglerighteq", "Vdash", "shortmid",
        "trianglelefteq", "vDash", "Vvdash", "shortparallel", "between", "pitchfork",
@@ -156,15 +243,15 @@ int const nr_latex_ams_rel = sizeof(latex_ams_rel) / sizeof(char const *);
 
 char const * latex_ams_nrel[] = {
        "nless", "nleq", "nleqslant", "ngeqslant", "ngeqq", "gneq",
-       "nleqq", "lneq", "lneqq","gneqq", "gvertneqq", "gnsim",
+       "nleqq", "lneq", "lneqq", "gneqq", "gvertneqq", "gnsim",
        "lvertneqq", "lnsim", "lnapprox", "gnapprox", "nsucc", "nsucceq",
        "nprec", "npreceq", "precnsim","succnsim", "succnapprox", "ncong",
        "precnapprox", "nsim", "nshortmid", "nshortparallel", "nparallel", "nvDash",
 
-       "nmid", "nvdash", "nvDash","nVDash", "ntriangleright", "ntrianglerighteq",
+       "nmid", "nvdash", "nvDash", "nVDash", "ntriangleright", "ntrianglerighteq",
        "ntriangleleft", "ntrianglelefteq", "nsubseteq", "nsupseteq", "nsupseteqq", "supsetneq",
        "subsetneq", "varsubsetneq", "subsetneqq", "varsupsetneq", "supsetneqq", "varsupsetneqq",
-       "varsubsetneqq", "ngtr", "ngeq","", "", ""
+       "varsubsetneqq", "ngtr", "ngeq", "", "", ""
 };
 
 int const nr_latex_ams_nrel = sizeof(latex_ams_nrel) / sizeof(char const *);
@@ -182,3 +269,103 @@ char const * latex_ams_ops[] = {
 };
 
 int const nr_latex_ams_ops = sizeof(latex_ams_ops) / sizeof(char const *);
+
+
+namespace {
+
+struct XPMmap {
+       char const * key;
+       char const * value;
+};
+
+
+bool operator<(XPMmap const & lhs, XPMmap const & rhs)
+{
+               return compare(lhs.key, rhs.key) < 0;
+}
+
+
+struct CompareKey {
+       CompareKey(string const & name) : name_(name) {}
+       bool operator()(XPMmap const & other) {
+               return compare(other.key, name_.c_str()) == 0;
+       }
+private:
+       string const name_;
+};
+
+
+XPMmap sorted_xpm_map[] = {
+       { "Bumpeq", "bumpeq2" },
+       { "Cap", "cap2" },
+       { "Cup", "cup2" },
+       { "Delta", "delta2" },
+       { "Downarrow", "downarrow2" },
+       { "Gamma", "gamma2" },
+       { "Lambda", "lambda2" },
+       { "Leftarrow", "leftarrow2" },
+       { "Leftrightarrow", "leftrightarrow2" },
+       { "Longleftarrow", "longleftarrow2" },
+       { "Longleftrightarrow", "longleftrightarrow2" },
+       { "Longrightarrow", "longrightarrow2" },
+       { "Omega", "omega2" },
+       { "Phi", "phi2" },
+       { "Pi", "pi2" },
+       { "Psi", "psi2" },
+       { "Rightarrow", "rightarrow2" },
+       { "Sigma", "sigma2" },
+       { "Subset", "subset2" },
+       { "Supset", "supset2" },
+       { "Theta", "theta2" },
+       { "Uparrow", "uparrow2" },
+       { "Updownarrow", "updownarrow2" },
+       { "Upsilon", "upsilon2" },
+       { "Vdash", "vdash3" },
+       { "Xi", "xi2" },
+       { "nLeftarrow", "nleftarrow2" },
+       { "nLeftrightarrow", "nleftrightarrow2" },
+       { "nRightarrow", "nrightarrow2" },
+       { "nVDash", "nvdash3" },
+       { "nvDash", "nvdash2" },
+       { "textrm_Å", "textrm_A" },
+       { "textrm_Ø", "textrm_0" },
+       { "vDash", "vdash2" }
+};
+
+size_t const nr_sorted_xpm_map = sizeof(sorted_xpm_map) / sizeof(XPMmap);
+
+} // namespace anon
+
+
+string const find_xpm(string const & name)
+{
+       XPMmap const * const begin = sorted_xpm_map;
+       XPMmap const * const end = begin + nr_sorted_xpm_map;
+       Assert(lyx::sorted(begin, end));
+
+       XPMmap const * const it =
+               std::find_if(begin, end, CompareKey(name));
+
+       string xpm_name;
+       if (it != end)
+               xpm_name = it->value;
+       else {
+               xpm_name = subst(name, "_", "underscore");
+               xpm_name = subst(xpm_name, ' ', '_');
+
+               // This way we can have "math-delim { }" on the toolbar.
+               xpm_name = subst(xpm_name, "(", "lparen");
+               xpm_name = subst(xpm_name, ")", "rparen");
+               xpm_name = subst(xpm_name, "[", "lbracket");
+               xpm_name = subst(xpm_name, "]", "rbracket");
+               xpm_name = subst(xpm_name, "{", "lbrace");
+               xpm_name = subst(xpm_name, "}", "rbrace");
+               xpm_name = subst(xpm_name, "|", "bars");
+       }
+
+       lyxerr[Debug::GUI] << "find_xpm(" << name << ")\n"
+                          << "Looking for math XPM called \""
+                          << xpm_name << '"' << std::endl;
+
+       return LibFileSearch("images/math/", xpm_name, "xpm");
+}