summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buttons-advanced.ui47
-rw-r--r--src/math-buttons.c61
-rw-r--r--src/mp-equation.c46
3 files changed, 148 insertions, 6 deletions
diff --git a/src/buttons-advanced.ui b/src/buttons-advanced.ui
index c668b25..df93b8d 100644
--- a/src/buttons-advanced.ui
+++ b/src/buttons-advanced.ui
@@ -766,8 +766,8 @@
</child>
</object>
<packing>
- <property name="left_attach">9</property>
- <property name="top_attach">4</property>
+ <property name="left_attach">10</property>
+ <property name="top_attach">0</property>
</packing>
</child>
<child>
@@ -861,7 +861,7 @@
<signal name="clicked" handler="button_cb" swapped="no"/>
</object>
<packing>
- <property name="left_attach">10</property>
+ <property name="left_attach">9</property>
<property name="top_attach">4</property>
</packing>
</child>
@@ -949,7 +949,46 @@
</packing>
</child>
<child>
- <placeholder/>
+ <object class="GtkButton" id="calc_const_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked" handler="const_cb" swapped="no"/>
+ <child>
+ <object class="GtkBox" id="hbox3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">const</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkArrow" id="arrow3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="arrow_type">down</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">10</property>
+ <property name="top_attach">4</property>
+ </packing>
</child>
</object>
</child>
diff --git a/src/math-buttons.c b/src/math-buttons.c
index 50b15a7..22d8570 100644
--- a/src/math-buttons.c
+++ b/src/math-buttons.c
@@ -45,6 +45,7 @@ struct MathButtonsPrivate
GtkWidget *shift_left_menu, *shift_right_menu;
GtkWidget *function_menu;
+ GtkWidget *const_menu;
GList *superscript_toggles;
GList *subscript_toggles;
@@ -125,6 +126,9 @@ static ButtonData button_data[] = {
{"function", NULL, FUNCTION,
/* Tooltip for the additional functions button */
N_("Additional Functions")},
+ {"const", NULL, FUNCTION,
+ /* Tooltip for the additional constant button */
+ N_("Additional constants")},
{"x_pow_y", "^", FUNCTION,
/* Tooltip for the exponent button */
N_("Exponent [^ or **]")},
@@ -1021,6 +1025,63 @@ function_cb(GtkWidget *widget, MathButtons *buttons)
popup_button_menu(widget, GTK_MENU(buttons->priv->function_menu));
}
+static void
+insert_const_cb(GtkWidget *widget, MathButtons *buttons)
+{
+ math_equation_insert(buttons->priv->equation, g_object_get_data(G_OBJECT(widget), "const"));
+}
+
+
+void const_cb(GtkWidget *widget, MathButtons *buttons);
+G_MODULE_EXPORT
+void
+const_cb(GtkWidget *widget, MathButtons *buttons)
+{
+ if (!buttons->priv->const_menu) {
+ gint i;
+ GtkWidget *menu;
+ struct
+ {
+ gchar *name, *constant;
+ } constants[] =
+ {
+ { /* Tooltip for the c₀ component button */
+ N_("Velocity of Light"), "c₀" },
+ { /* Tooltip for the μ₀ component button */
+ N_("Magnetic constant"), "μ₀" },
+ { /* Tooltip for the ε₀ button */
+ N_("Electric constant"), "ε₀" },
+ { /* Tooltip for the G button */
+ N_("Newtonian constant of gravitation"), "G" },
+ { /* Tooltip for the h button */
+ N_("Planck constant"), "h" },
+ { /* Tooltip for the e button */
+ N_("Elementary charge"), "e" },
+ { /* Tooltip for the mₑ button */
+ N_("Electron mass"), "mₑ" },
+ { /* Tooltip for the mₚ button */
+ N_("Proton mass"), "mₚ" },
+ { /* Tooltip for the Nₐ button */
+ N_("Avogrado constant"), "Nₐ" },
+ { NULL, NULL }
+ };
+
+ menu = buttons->priv->const_menu = gtk_menu_new();
+ gtk_menu_set_reserve_toggle_size(GTK_MENU(menu), FALSE);
+
+ for (i = 0; constants[i].name != NULL; i++) {
+ GtkWidget *item;
+
+ item = gtk_menu_item_new_with_label(_(constants[i].name));
+ g_object_set_data(G_OBJECT(item), "const", g_strdup(constants[i].constant));
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+ g_signal_connect(item, "activate", G_CALLBACK(insert_const_cb), buttons);
+ gtk_widget_show(item);
+ }
+ }
+
+ popup_button_menu(widget, GTK_MENU(buttons->priv->const_menu));
+}
void factorize_cb(GtkWidget *widget, MathButtons *buttons);
G_MODULE_EXPORT
diff --git a/src/mp-equation.c b/src/mp-equation.c
index b80408e..fd3ea5a 100644
--- a/src/mp-equation.c
+++ b/src/mp-equation.c
@@ -18,7 +18,19 @@ static int
variable_is_defined(ParserState *state, const char *name)
{
/* FIXME: Make more generic */
- if (strcmp(name, "e") == 0 || strcmp(name, "i") == 0 || strcmp(name, "π") == 0 || strcmp(name, "pi") == 0)
+ if (strcmp(name, "e") == 0 ||
+ strcmp(name, "i") == 0 ||
+ strcmp(name, "π") == 0 ||
+ strcmp(name, "pi") == 0 ||
+ strcmp(name, "c₀") == 0 ||
+ strcmp(name, "μ₀") == 0 ||
+ strcmp(name, "ε₀") == 0 ||
+ strcmp(name, "G") == 0 ||
+ strcmp(name, "h") == 0 ||
+ strcmp(name, "e") == 0 ||
+ strcmp(name, "mₑ") == 0 ||
+ strcmp(name, "mₚ") == 0 ||
+ strcmp(name, "Nₐ") == 0)
return 1;
if (state->options->variable_is_defined)
return state->options->variable_is_defined(name, state->options->callback_data);
@@ -37,6 +49,24 @@ get_variable(ParserState *state, const char *name, MPNumber *z)
mp_get_i(z);
else if (strcmp(name, "π") == 0 || strcmp(name, "pi") == 0)
mp_get_pi(z);
+ else if (strcmp(name, "c₀") == 0)
+ mp_set_from_string("299792458", 10, z); /* velocity of light */
+ else if (strcmp(name, "μ₀") == 0)
+ mp_set_from_string("0.0000012566370614", 10, z); /* magnetic constant */
+ else if (strcmp(name, "ε₀") == 0)
+ mp_set_from_string("0.000000000008854187817", 10, z); /* electric constant */
+ else if (strcmp(name, "G") == 0)
+ mp_set_from_string("0.0000000000667310", 10, z); /* Newtonian constant of gravitation */
+ else if (strcmp(name, "h") == 0)
+ mp_set_from_string("0.000000000000000000000000000000000662606876", 10, z); /* Planck constant */
+ else if (strcmp(name, "e") == 0)
+ mp_set_from_string("0.0000000000000000001602176462", 10, z); /* elementary charge */
+ else if (strcmp(name, "mₑ") == 0)
+ mp_set_from_string("0.000000000000000000000000000000910938188", 10, z); /* electron mass */
+ else if (strcmp(name, "mₚ") == 0)
+ mp_set_from_string("0.00000000000000000000000000167262158", 10, z); /* proton mass */
+ else if (strcmp(name, "Nₐ") == 0)
+ mp_set_from_string("602214199000000000000000", 10, z); /* Avogrado constant */
else if (state->options->get_variable)
result = state->options->get_variable(name, z, state->options->callback_data);
else
@@ -49,7 +79,19 @@ static void
set_variable(ParserState *state, const char *name, const MPNumber *x)
{
// Reserved words, e, π, mod, and, or, xor, not, abs, log, ln, sqrt, int, frac, sin, cos, ...
- if (strcmp(name, "e") == 0 || strcmp(name, "i") == 0 || strcmp(name, "π") == 0 || strcmp(name, "pi") == 0)
+ if (strcmp(name, "e") == 0 ||
+ strcmp(name, "i") == 0 ||
+ strcmp(name, "π") == 0 ||
+ strcmp(name, "pi") == 0 ||
+ strcmp(name, "c₀") == 0 ||
+ strcmp(name, "μ₀") == 0 ||
+ strcmp(name, "ε₀") == 0 ||
+ strcmp(name, "G") == 0 ||
+ strcmp(name, "h") == 0 ||
+ strcmp(name, "e") == 0 ||
+ strcmp(name, "mₑ") == 0 ||
+ strcmp(name, "mₚ") == 0 ||
+ strcmp(name, "Nₐ") == 0)
return; // FALSE
if (state->options->set_variable)