* 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
+ * \author Angus Leeming
*
* Full author contact details are available in file CREDITS
*/
#include <config.h>
#include "ControlMath.h"
-#include "ViewBase.h"
-
+#include "Kernel.h"
#include "debug.h"
#include "funcrequest.h"
-#include "frontends/LyXView.h"
-
+#include "support/LAssert.h"
+#include "support/lyxalgo.h" // sorted
#include "support/lstrings.h"
#include "support/filetools.h"
-ControlMath::ControlMath(LyXView & lv, Dialogs & d)
- : ControlDialogBD(lv, d), active_(0)
-{}
+using namespace lyx::support;
-void ControlMath::apply()
-{
- view().apply();
-}
+ControlMath::ControlMath(Dialog & dialog)
+ : Dialog::Controller(dialog)
+{}
void ControlMath::dispatchFunc(kb_action action, string const & arg) const
{
- lv_.dispatch(FuncRequest(action, arg));
+ kernel().dispatch(FuncRequest(action, arg));
}
-void ControlMath::insertSymbol(string const & sym, bool bs) const
+void ControlMath::dispatchInsert(string const & name) const
{
- if (bs)
- lv_.dispatch(FuncRequest(LFUN_INSERT_MATH, '\\' + sym));
- else
- lv_.dispatch(FuncRequest(LFUN_INSERT_MATH, sym));
+ dispatchFunc(LFUN_INSERT_MATH, '\\' + name);
}
-void ControlMath::addDaughter(void * key, ViewBase * v,
- ButtonControllerBase * bc)
+void ControlMath::dispatchSubscript() const
{
- if (daughters_.find(key) != daughters_.end())
- return;
-
- daughters_[key] = DaughterPtr(new GUIMathSub(lv_, d_, *this, v, bc));
+ dispatchFunc(LFUN_SUBSCRIPT);
}
-void ControlMath::showDaughter(void * key)
+void ControlMath::dispatchSuperscript() const
{
- Store::iterator it = daughters_.find(key);
- GUIMathSub * const new_active =
- (it == daughters_.end()) ? 0 : it->second.get();
-
- if (active_ != new_active) {
- if (active_ )
- active_->controller().hide();
- active_ = new_active;
- }
-
- if (active_)
- active_->controller().show();
+ dispatchFunc(LFUN_SUPERSCRIPT);
}
-
-ControlMathSub::ControlMathSub(LyXView & lv, Dialogs & d, ControlMath const & p)
- : ControlDialogBD(lv, d),
- parent_(p)
-{}
+void ControlMath::dispatchCubeRoot() const
+{
+ dispatchFunc(LFUN_INSERT_MATH, "\\root");
+ dispatchFunc(LFUN_SELFINSERT, "3");
+ dispatchFunc(LFUN_RIGHT);
+}
-void ControlMathSub::apply()
+void ControlMath::dispatchMatrix(string const & str) const
{
- view().apply();
+ dispatchFunc(LFUN_INSERT_MATRIX, str);
}
-void ControlMathSub::dispatchFunc(kb_action action, string const & arg) const
+void ControlMath::dispatchDelim(string const & str) const
{
- parent_.dispatchFunc(action, arg);
+ dispatchFunc(LFUN_MATH_DELIM, str);
}
-void ControlMathSub::insertSymbol(string const & sym, bool bs) const
+void ControlMath::dispatchToggleDisplay() const
{
- parent_.insertSymbol(sym, bs);
+ dispatchFunc(LFUN_MATH_DISPLAY);
}
-GUIMathSub::GUIMathSub(LyXView & lv, Dialogs & d,
- ControlMath const & p,
- ViewBase * v,
- ButtonControllerBase * bc)
- : controller_(lv, d, p), bc_(bc), view_(v)
+void ControlMath::showDialog(string const & name) const
{
- controller_.setView(*view_);
- controller_.setButtonController(*bc_);
- view_->setController(controller_);
+ dispatchFunc(LFUN_DIALOG_SHOW, name);
}
"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;
"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",
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)
{
-#warning Use a static table for this (Lgb)
- // And get O(log n) lookup (Lgb)
-
- string xpm_name = subst(name, ' ', '_');
- if (xpm_name == "(") xpm_name = "lparen";
- else if (xpm_name == ")") xpm_name = "rparen";
- else if (xpm_name == "[") xpm_name = "lbracket";
- else if (xpm_name == "]") xpm_name = "rbracket";
- else if (xpm_name == "{") xpm_name = "lbrace";
- else if (xpm_name == "}") xpm_name = "rbrace";
- else if (xpm_name == "|") xpm_name = "bars";
- else if (xpm_name == "_") xpm_name = "underscore";
- else if (xpm_name == "textrm_Å") xpm_name = "textrm_A";
- else if (xpm_name == "textrm_Ø") xpm_name = "textrm_0";
- else if (xpm_name == "Bumpeq") xpm_name = "bumpeq2";
- else if (xpm_name == "Cap") xpm_name = "cap2";
- else if (xpm_name == "Cup") xpm_name = "cup2";
- else if (xpm_name == "Delta") xpm_name = "delta2";
- else if (xpm_name == "Downarrow") xpm_name = "downarrow2";
- else if (xpm_name == "Gamma") xpm_name = "gamma2";
- else if (xpm_name == "Lambda") xpm_name = "lambda2";
- else if (xpm_name == "Leftarrow") xpm_name = "leftarrow2";
- else if (xpm_name == "Leftrightarrow") xpm_name = "leftrightarrow2";
- else if (xpm_name == "Longleftarrow") xpm_name = "longleftarrow2";
- else if (xpm_name == "Longleftrightarrow") xpm_name = "longleftrightarrow2";
- else if (xpm_name == "Longrightarrow") xpm_name = "longrightarrow2";
- else if (xpm_name == "nLeftarrow") xpm_name = "nleftarrow2";
- else if (xpm_name == "nLeftrightarrow") xpm_name = "nleftrightarrow2";
- else if (xpm_name == "nRightarrow") xpm_name = "nrightarrow2";
- else if (xpm_name == "nvDash") xpm_name = "nvdash2";
- else if (xpm_name == "nVDash") xpm_name = "nvdash3";
- else if (xpm_name == "Omega") xpm_name = "omega2";
- else if (xpm_name == "Phi") xpm_name = "phi2";
- else if (xpm_name == "Pi") xpm_name = "pi2";
- else if (xpm_name == "Psi") xpm_name = "psi2";
- else if (xpm_name == "Rightarrow") xpm_name = "rightarrow2";
- else if (xpm_name == "Sigma") xpm_name = "sigma2";
- else if (xpm_name == "Subset") xpm_name = "subset2";
- else if (xpm_name == "Supset") xpm_name = "supset2";
- else if (xpm_name == "Theta") xpm_name = "theta2";
- else if (xpm_name == "Uparrow") xpm_name = "uparrow2";
- else if (xpm_name == "Updownarrow") xpm_name = "updownarrow2";
- else if (xpm_name == "Upsilon") xpm_name = "upsilon2";
- else if (xpm_name == "vDash") xpm_name = "vdash2";
- else if (xpm_name == "Vdash") xpm_name = "vdash3";
- else if (xpm_name == "Xi") xpm_name = "xi2";
-
- lyxerr[Debug::GUI] << "Looking for math XPM called \""
- << xpm_name << '"' << std::endl;
+ 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");
}