summaryrefslogtreecommitdiff
path: root/src/math-buttons.c
diff options
context:
space:
mode:
authormbkma <[email protected]>2019-04-23 21:07:07 +0200
committerraveit65 <[email protected]>2019-05-07 21:13:40 +0200
commit3d27093a45116cc0ecbf1b568b9cc5efed98e2a3 (patch)
tree0f9be9bc8c240ef8c43976da1e3ded73a74abcb1 /src/math-buttons.c
parent47c3325358011aba0e1db6d2ee430237d51d13db (diff)
downloadmate-calc-3d27093a45116cc0ecbf1b568b9cc5efed98e2a3.tar.bz2
mate-calc-3d27093a45116cc0ecbf1b568b9cc5efed98e2a3.tar.xz
mp-equation: add pre-defined physical constants
This adds some fundamental physical constants: - Velocity of Light "c₀", 299,792,458 m/s - Magnetic constant, "μ₀", 1.2566370614×10⁻ N/A² - Electric constant, "ε₀", 8.85418782×10⁻¹² s⁴A²/m³kg - Newtonian constant of gravitation, "G", 6.67408×10⁻¹¹ m³/(s²kg) - Planck constant, "h", 6.62607004×10⁻³⁴ m²kg/s - Elementary charge, "e", 1.6021766208(98)×10⁻¹⁹ C - Electron mass, "mₑ", 9.10938356×10⁻³¹ kg - Proton mass, "mₚ", 1.672621898(21)×10⁻²⁷ kg - Avogrado constant, "Nₐ", 6.02214086×10²³ mol⁻¹ They are taken from https://en.wikipedia.org/wiki/Physical_constant#Universal_constants To insert them one would enter the corresponding symbol or use the gui. They are set to a MPNumber from string.
Diffstat (limited to 'src/math-buttons.c')
-rw-r--r--src/math-buttons.c61
1 files changed, 61 insertions, 0 deletions
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