[Xfce4-commits] <xfce4-calculator-plugin:master> Let the user choose angle unit (degrees/radians) for trigonometrics.
Erik Edelmann
noreply at xfce.org
Tue Jun 29 22:50:13 CEST 2010
Updating branch refs/heads/master
to 7748f7ee701e374c3ac6a77f0dd397560798200f (commit)
from 2f45f1ad6620748ad708b2541859b77a03f15f3d (commit)
commit 7748f7ee701e374c3ac6a77f0dd397560798200f
Author: Erik Edelmann <erik_e at iki.fi>
Date: Mon Mar 22 23:52:48 2010 +0200
Let the user choose angle unit (degrees/radians) for trigonometrics.
TODO | 2 -
panel-plugin/calculator.c | 53 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+), 2 deletions(-)
diff --git a/TODO b/TODO
index 4a97573..b5959c1 100644
--- a/TODO
+++ b/TODO
@@ -2,8 +2,6 @@ TODO before 1.0
===============
- More configurability:
- - Let the user choose between radians and degrees for trigonometric
- functions
- Let the user choose history length
- Let the user choose number of significant digits in output
diff --git a/panel-plugin/calculator.c b/panel-plugin/calculator.c
index e385261..b1f4fea 100644
--- a/panel-plugin/calculator.c
+++ b/panel-plugin/calculator.c
@@ -46,6 +46,8 @@ typedef struct {
GtkWidget *ebox;
GtkWidget *hvbox;
GtkWidget *combo;
+ GtkWidget *degrees_button;
+ GtkWidget *radians_button;
GList *expr_hist; // Expression history
@@ -294,6 +296,27 @@ calc_plugin_size_changed (GtkSpinButton *spin, CalcPlugin *calc)
}
+/* Called when the "trigonometrics use degree/radians" menu items change state.
+
+ Note that since they are radio buttons, grouped together, they will allways
+ change state both at the same time - one to "active" and the other to "not
+ active". Since we actually need only one call per time, we'll ignore the call
+ for the de-activated button. */
+
+static void angle_unit_chosen(GtkCheckMenuItem *button, CalcPlugin *calc)
+{
+ if (!gtk_check_menu_item_get_active(button))
+ return;
+
+ if (button == (GtkCheckMenuItem *)calc->degrees_button)
+ calc->degrees = TRUE;
+ else {
+ g_assert(button == (GtkCheckMenuItem *)calc->radians_button);
+ calc->degrees = FALSE;
+ }
+}
+
+
static void calc_dialog_response(GtkWidget *dialog, gint response,
CalcPlugin *calc)
{
@@ -367,6 +390,7 @@ static void calc_configure(XfcePanelPlugin *plugin, CalcPlugin *calc)
static void calc_construct(XfcePanelPlugin *plugin)
{
CalcPlugin *calc;
+ GtkWidget *degrees, *radians;
/* Make sure the comma sign (",") isn't treated as a decimal separator. */
setlocale(LC_NUMERIC, "C");
@@ -392,4 +416,33 @@ static void calc_construct(XfcePanelPlugin *plugin)
xfce_panel_plugin_menu_show_configure(plugin);
g_signal_connect(G_OBJECT(plugin), "configure-plugin",
G_CALLBACK(calc_configure), calc);
+
+
+ // Add controls for choosing angle unit to the menu.
+ degrees = gtk_radio_menu_item_new_with_label(
+ NULL,
+ "Trigonometrics use degrees");
+ radians = gtk_radio_menu_item_new_with_label(
+ gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(degrees)),
+ "Trigonometrics use radians");
+
+ if (calc->degrees)
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(degrees), TRUE);
+ else
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(radians), TRUE);
+
+ g_signal_connect(G_OBJECT(degrees), "toggled",
+ G_CALLBACK(angle_unit_chosen), calc);
+
+ g_signal_connect(G_OBJECT(radians), "toggled",
+ G_CALLBACK(angle_unit_chosen), calc);
+
+ gtk_widget_show(degrees);
+ gtk_widget_show(radians);
+
+ xfce_panel_plugin_menu_insert_item(plugin, GTK_MENU_ITEM(degrees));
+ xfce_panel_plugin_menu_insert_item(plugin, GTK_MENU_ITEM(radians));
+
+ calc->degrees_button = degrees;
+ calc->radians_button = radians;
}
More information about the Xfce4-commits
mailing list