diff options
author | Steve Zesch <[email protected]> | 2012-11-24 20:44:45 -0500 |
---|---|---|
committer | Steve Zesch <[email protected]> | 2012-11-24 20:44:45 -0500 |
commit | 6b24c91d3aa81fdb99500c8c2c12f830fabaefb6 (patch) | |
tree | 6a0038ecfaa77e156ee2cc9059220685091217d7 /src/math-buttons.c | |
parent | a10375c2851e8569353c0da9921b8d0d9cbea2e6 (diff) | |
download | mate-calc-6b24c91d3aa81fdb99500c8c2c12f830fabaefb6.tar.bz2 mate-calc-6b24c91d3aa81fdb99500c8c2c12f830fabaefb6.tar.xz |
Update codebase.
Diffstat (limited to 'src/math-buttons.c')
-rw-r--r-- | src/math-buttons.c | 864 |
1 files changed, 210 insertions, 654 deletions
diff --git a/src/math-buttons.c b/src/math-buttons.c index d33422b..cd28ee7 100644 --- a/src/math-buttons.c +++ b/src/math-buttons.c @@ -1,31 +1,26 @@ -/* Copyright (c) 2008-2009 Robert Ancell +/* + * Copyright (C) 2008-2011 Robert Ancell * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. See http://www.gnu.org/copyleft/gpl.html the full text of the + * license. */ #include <glib/gi18n.h> #include "math-buttons.h" +#include "math-converter.h" +#include "math-variable-popup.h" #include "financial.h" -#include "currency.h" +#include "mp-serializer.h" enum { PROP_0, PROP_EQUATION, - PROP_MODE + PROP_MODE, + PROP_PROGRAMMING_BASE }; static GType button_mode_type; @@ -39,9 +34,9 @@ struct MathButtonsPrivate ButtonMode mode; gint programming_base; - GtkBuilder *basic_ui, *advanced_ui, *financial_ui, *programming_ui; + MathConverter *converter; - GdkColor color_numbers, color_action, color_operator, color_function, color_memory, color_group; + GtkBuilder *basic_ui, *advanced_ui, *financial_ui, *programming_ui; GtkWidget *bas_panel, *adv_panel, *fin_panel, *prog_panel; GtkWidget *active_panel; @@ -53,18 +48,11 @@ struct MathButtonsPrivate GList *superscript_toggles; GList *subscript_toggles; - GtkWidget *angle_combo; - GtkWidget *angle_label; - GtkWidget *base_combo; GtkWidget *base_label; GtkWidget *bit_panel; GtkWidget *bit_labels[MAXBITS]; - GtkWidget *source_currency_combo; - GtkWidget *target_currency_combo; - GtkWidget *currency_label; - GtkWidget *character_code_dialog; GtkWidget *character_code_entry; }; @@ -178,15 +166,6 @@ static ButtonData button_data[] = { {"tangent", "tan ", FUNCTION, /* Tooltip for the tangent button */ N_("Tangent")}, - {"inverse_sine", "asin", FUNCTION, - /* Tooltip for the inverse sine button */ - N_("Inverse Sine")}, - {"inverse_cosine", "acos", FUNCTION, - /* Tooltip for the inverse cosine button */ - N_("Inverse Cosine")}, - {"inverse_tangent", "atan", FUNCTION, - /* Tooltip for the inverse tangent button */ - N_("Inverse Tangent")}, {"hyperbolic_sine", "sinh ", FUNCTION, /* Tooltip for the hyperbolic sine button */ N_("Hyperbolic Sine")}, @@ -224,11 +203,11 @@ static ButtonData button_data[] = { /* Tooltip for the imaginary component button */ N_("Imaginary Component")}, {"ones_complement", "ones ", FUNCTION, - /* Tooltip for the ones complement button */ - N_("Ones Complement")}, + /* Tooltip for the ones' complement button */ + N_("Ones' Complement")}, {"twos_complement", "twos ", FUNCTION, - /* Tooltip for the twos complement button */ - N_("Twos Complement")}, + /* Tooltip for the two's complement button */ + N_("Two's Complement")}, {"trunc", "trunc ", FUNCTION, /* Tooltip for the truncate button */ N_("Truncate")}, @@ -238,12 +217,9 @@ static ButtonData button_data[] = { {"end_group", ")", GROUP, /* Tooltip for the end group button */ N_("End Group [)]")}, - {"store", NULL, MEMORY, - /* Tooltip for the assign variable button */ - N_("Assign Variable")}, - {"recall", NULL, MEMORY, - /* Tooltip for the insert variable button */ - N_("Insert Variable")}, + {"memory", NULL, MEMORY, + /* Tooltip for the memory button */ + N_("Memory")}, {"character", NULL, MEMORY, /* Tooltip for the insert character code button */ N_("Insert Character Code")}, @@ -261,10 +237,10 @@ static ButtonData button_data[] = { N_("Undo [Ctrl+Z]")}, {"shift_left", NULL, ACTION, /* Tooltip for the shift left button */ - N_("Shift Left [<<]")}, + N_("Shift Left")}, {"shift_right", NULL, ACTION, /* Tooltip for the shift right button */ - N_("Shift Right [>>]")}, + N_("Shift Right")}, {"finc_compounding_term", NULL, FUNCTION, /* Tooltip for the compounding term button */ N_("Compounding Term")}, @@ -298,11 +274,6 @@ static ButtonData button_data[] = { {NULL, NULL, 0, NULL} }; -typedef enum { - CURRENCY_TARGET_UPPER, - CURRENCY_TARGET_LOWER -} CurrencyTargetRow; - /* The names of each field in the dialogs for the financial functions */ static char *finc_dialog_fields[][5] = { {"ctrm_pint", "ctrm_fv", "ctrm_pv", NULL, NULL}, @@ -322,37 +293,9 @@ static char *finc_dialog_fields[][5] = { MathButtons * math_buttons_new(MathEquation *equation) { - return g_object_new (math_buttons_get_type(), "equation", equation, NULL); -} - - -static void -set_tint (GtkWidget *widget, GdkColor *tint, gint alpha) -{ - // hell no. It's a calculator, not a rainbow - return; - - GtkStyle *style; - int j; - - if (!widget) - return; - - gtk_widget_ensure_style(widget); - style = gtk_widget_get_style(widget); - - for (j = 0; j < 5; j++) { - GdkColor color; - - color.red = (style->bg[j].red * (10 - alpha) + tint->red * alpha) / 10; - color.green = (style->bg[j].green * (10 - alpha) + tint->green * alpha) / 10; - color.blue = (style->bg[j].blue * (10 - alpha) + tint->blue * alpha) / 10; - gdk_colormap_alloc_color(gdk_colormap_get_system(), &color, FALSE, TRUE); - gtk_widget_modify_bg(widget, j, &color); - } + return g_object_new(math_buttons_get_type(), "equation", equation, NULL); } - static void set_data(GtkBuilder *ui, const gchar *object_name, const gchar *name, const char *value) { @@ -366,7 +309,7 @@ set_data(GtkBuilder *ui, const gchar *object_name, const gchar *name, const char static void set_int_data(GtkBuilder *ui, const gchar *object_name, const gchar *name, gint value) { - GObject *object; + GObject *object; object = gtk_builder_get_object(ui, object_name); if (object) g_object_set_data(object, name, GINT_TO_POINTER(value)); @@ -392,9 +335,7 @@ load_finc_dialogs(MathButtons *buttons) for (i = 0; finc_dialog_fields[i][0] != NULL; i++) { for (j = 0; finc_dialog_fields[i][j]; j++) { GObject *o; - o = gtk_builder_get_object(buttons->priv->financial_ui, finc_dialog_fields[i][j]); - if(!o) - printf("missing '%s'\n", finc_dialog_fields[i][j]); + o = gtk_builder_get_object (buttons->priv->financial_ui, finc_dialog_fields[i][j]); g_object_set_data(o, "finc_field", GINT_TO_POINTER(j)); g_object_set_data(o, "finc_dialog", GINT_TO_POINTER(i)); } @@ -403,71 +344,6 @@ load_finc_dialogs(MathButtons *buttons) static void -update_angle_label (MathButtons *buttons) -{ - MPNumber x; - MPNumber pi, max_value, min_value, fraction, input, output; - char *label, input_text[1024], output_text[1024]; - - if (!buttons->priv->angle_label) - return; - - if (!math_equation_get_number(buttons->priv->equation, &x)) - return; - - mp_get_pi(&pi); - switch (math_equation_get_angle_units(buttons->priv->equation)) { - default: - case MP_DEGREES: - label = g_strdup(""); - break; - case MP_RADIANS: - /* Clip to the range ±2π */ - mp_multiply_integer(&pi, 2, &max_value); - mp_invert_sign(&max_value, &min_value); - if (!mp_is_equal(&x, &max_value) && !mp_is_equal(&x, &min_value)) { - mp_divide(&x, &max_value, &fraction); - mp_fractional_component(&fraction, &fraction); - mp_multiply(&fraction, &max_value, &input); - } - else { - mp_set_from_mp(&x, &input); - mp_set_from_integer(mp_is_negative(&input) ? -1 : 1, &fraction); - } - mp_cast_to_string(&input, 10, 10, 2, false, input_text, 1024); - - mp_multiply_integer(&fraction, 360, &output); - mp_cast_to_string(&output, 10, 10, 2, false, output_text, 1024); - label = g_strdup_printf(_("%s radians = %s degrees"), input_text, output_text); - break; - case MP_GRADIANS: - /* Clip to the range ±400 */ - mp_set_from_integer(400, &max_value); - mp_invert_sign(&max_value, &min_value); - if (!mp_is_equal(&x, &max_value) && !mp_is_equal(&x, &min_value)) { - mp_divide(&x, &max_value, &fraction); - mp_fractional_component(&fraction, &fraction); - mp_multiply(&fraction, &max_value, &input); - } - else { - mp_set_from_mp(&x, &input); - mp_set_from_integer(mp_is_negative(&input) ? -1 : 1, &fraction); - } - - mp_cast_to_string(&input, 10, 10, 2, false, input_text, 1024); - - mp_multiply_integer(&fraction, 360, &output); - mp_cast_to_string(&output, 10, 10, 2, false, output_text, 1024); - label = g_strdup_printf(_("%s gradians = %s degrees"), input_text, output_text); - break; - } - - gtk_label_set_text(GTK_LABEL(buttons->priv->angle_label), label); - g_free(label); -} - - -static void update_bit_panel(MathButtons *buttons) { MPNumber x; @@ -479,7 +355,7 @@ update_bit_panel(MathButtons *buttons) if (!buttons->priv->bit_panel) return; - + enabled = math_equation_get_number(buttons->priv->equation, &x); if (enabled) { @@ -495,7 +371,7 @@ update_bit_panel(MathButtons *buttons) gtk_widget_set_sensitive(buttons->priv->bit_panel, enabled); gtk_widget_set_sensitive(buttons->priv->base_label, enabled); - + if (!enabled) return; @@ -509,24 +385,24 @@ update_bit_panel(MathButtons *buttons) gtk_label_set_text(GTK_LABEL(buttons->priv->bit_labels[i]), label); } - base = math_equation_get_base(buttons->priv->equation); + base = math_equation_get_base(buttons->priv->equation); label = g_string_new(""); if (base != 8) { if (label->len != 0) g_string_append(label, " = "); - g_string_append_printf(label, "%lo", bits); + g_string_append_printf(label, "%" G_GINT64_MODIFIER "o", bits); g_string_append(label, "₈"); } if (base != 10) { if (label->len != 0) g_string_append(label, " = "); - g_string_append_printf(label, "%lu", bits); + g_string_append_printf(label, "%" G_GINT64_MODIFIER "u", bits); g_string_append(label, "₁₀"); } if (base != 16) { if (label->len != 0) g_string_append(label, " = "); - g_string_append_printf(label, "%lX", bits); + g_string_append_printf(label, "%" G_GINT64_MODIFIER "X", bits); g_string_append(label, "₁₆"); } @@ -536,97 +412,13 @@ update_bit_panel(MathButtons *buttons) static void -update_currency_label(MathButtons *buttons) -{ - MPNumber x, value; - char *label; - - if (!buttons->priv->currency_label) - return; - - if (!math_equation_get_number(buttons->priv->equation, &x)) - return; - - if (currency_convert(&x, - math_equation_get_source_currency(buttons->priv->equation), - math_equation_get_target_currency(buttons->priv->equation), - &value)) { - char input_text[1024], output_text[1024]; - const char *source_symbol, *target_symbol; - int i; - - mp_cast_to_string(&x, 10, 10, 2, false, input_text, 1024); - mp_cast_to_string(&value, 10, 10, 2, false, output_text, 1024); - - for (i = 0; strcmp(math_equation_get_source_currency(buttons->priv->equation), currency_names[i].short_name) != 0; i++); - source_symbol = currency_names[i].symbol; - for (i = 0; strcmp(math_equation_get_target_currency(buttons->priv->equation), currency_names[i].short_name) != 0; i++); - target_symbol = currency_names[i].symbol; - - /* Translators: first and third %s are currency symbols, second - * and fourth are amounts in these currencies, you may want to change - * the order of these, example: $100 = €100 */ - label = g_strdup_printf(_("%s%s = %s%s"), - source_symbol, input_text, - target_symbol, output_text); - } - else - label = g_strdup(""); - - gtk_label_set_text(GTK_LABEL(buttons->priv->currency_label), label); - g_free(label); -} - - -static void display_changed_cb(MathEquation *equation, GParamSpec *spec, MathButtons *buttons) { - update_angle_label(buttons); - update_currency_label(buttons); update_bit_panel(buttons); } static void -angle_unit_combobox_changed_cb(GtkWidget *combo, MathButtons *buttons) -{ - MPAngleUnit value; - GtkTreeModel *model; - GtkTreeIter iter; - - model = gtk_combo_box_get_model(GTK_COMBO_BOX(combo)); - gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter); - gtk_tree_model_get(model, &iter, 1, &value, -1); - math_equation_set_angle_units(buttons->priv->equation, value); -} - - -static void -angle_unit_cb(MathEquation *equation, GParamSpec *spec, MathButtons *buttons) -{ - GtkTreeModel *model; - GtkTreeIter iter; - gboolean valid; - - model = gtk_combo_box_get_model(GTK_COMBO_BOX(buttons->priv->angle_combo)); - valid = gtk_tree_model_get_iter_first(model, &iter); - - while (valid) { - gint v; - - gtk_tree_model_get(model, &iter, 1, &v, -1); - if (v == math_equation_get_angle_units(buttons->priv->equation)) - break; - valid = gtk_tree_model_iter_next(model, &iter); - } - if (!valid) - valid = gtk_tree_model_get_iter_first(model, &iter); - - gtk_combo_box_set_active_iter(GTK_COMBO_BOX(buttons->priv->angle_combo), &iter); -} - - -static void base_combobox_changed_cb(GtkWidget *combo, MathButtons *buttons) { gint value; @@ -637,7 +429,7 @@ base_combobox_changed_cb(GtkWidget *combo, MathButtons *buttons) gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter); gtk_tree_model_get(model, &iter, 1, &value, -1); - math_equation_set_base(buttons->priv->equation, value); + math_buttons_set_programming_base(buttons, value); } @@ -647,7 +439,7 @@ base_changed_cb(MathEquation *equation, GParamSpec *spec, MathButtons *buttons) GtkTreeModel *model; GtkTreeIter iter; gboolean valid; - + if (buttons->priv->mode != PROGRAMMING) return; @@ -670,102 +462,6 @@ base_changed_cb(MathEquation *equation, GParamSpec *spec, MathButtons *buttons) } -static void -source_currency_combo_changed_cb(GtkWidget *combo, MathButtons *buttons) -{ - gchar *value; - GtkTreeModel *model; - GtkTreeIter iter; - - model = gtk_combo_box_get_model(GTK_COMBO_BOX(combo)); - gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter); - gtk_tree_model_get(model, &iter, 0, &value, -1); - - math_equation_set_source_currency(buttons->priv->equation, value); - g_free (value); -} - - -static void -source_currency_changed_cb(MathEquation *equation, GParamSpec *spec, MathButtons *buttons) -{ - GtkTreeModel *model; - GtkTreeIter iter; - gboolean valid; - - if (buttons->priv->mode != FINANCIAL) - return; - - model = gtk_combo_box_get_model(GTK_COMBO_BOX(buttons->priv->source_currency_combo)); - valid = gtk_tree_model_get_iter_first(model, &iter); - - while (valid) { - gchar *v; - gboolean matched; - - gtk_tree_model_get(model, &iter, 0, &v, -1); - matched = strcmp (math_equation_get_source_currency(buttons->priv->equation), v) == 0; - g_free (v); - if (matched) - break; - valid = gtk_tree_model_iter_next(model, &iter); - } - if (!valid) - valid = gtk_tree_model_get_iter_first(model, &iter); - - gtk_combo_box_set_active_iter(GTK_COMBO_BOX(buttons->priv->source_currency_combo), &iter); - update_currency_label(buttons); -} - - -static void -target_currency_combo_changed_cb(GtkWidget *combo, MathButtons *buttons) -{ - gchar *value; - GtkTreeModel *model; - GtkTreeIter iter; - - model = gtk_combo_box_get_model(GTK_COMBO_BOX(combo)); - gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter); - gtk_tree_model_get(model, &iter, 0, &value, -1); - - math_equation_set_target_currency(buttons->priv->equation, value); - g_free (value); -} - - -static void -target_currency_changed_cb(MathEquation *equation, GParamSpec *spec, MathButtons *buttons) -{ - GtkTreeModel *model; - GtkTreeIter iter; - gboolean valid; - - if (buttons->priv->mode != FINANCIAL) - return; - - model = gtk_combo_box_get_model(GTK_COMBO_BOX(buttons->priv->target_currency_combo)); - valid = gtk_tree_model_get_iter_first(model, &iter); - - while (valid) { - gchar *v; - gboolean matched; - - gtk_tree_model_get(model, &iter, 0, &v, -1); - matched = strcmp (math_equation_get_target_currency(buttons->priv->equation), v) == 0; - g_free (v); - if (matched) - break; - valid = gtk_tree_model_iter_next(model, &iter); - } - if (!valid) - valid = gtk_tree_model_get_iter_first(model, &iter); - - gtk_combo_box_set_active_iter(GTK_COMBO_BOX(buttons->priv->target_currency_combo), &iter); - update_currency_label(buttons); -} - - static GtkWidget * load_mode(MathButtons *buttons, ButtonMode mode) { @@ -781,6 +477,7 @@ load_mode(MathButtons *buttons, ButtonMode mode) GError *error = NULL; switch (mode) { + default: case BASIC: builder_ptr = &buttons->priv->basic_ui; builder_file = UI_BASIC_FILE; @@ -802,7 +499,7 @@ load_mode(MathButtons *buttons, ButtonMode mode) panel = &buttons->priv->prog_panel; break; } - + if (*panel) return *panel; @@ -814,7 +511,7 @@ load_mode(MathButtons *buttons, ButtonMode mode) g_clear_error(&error); } *panel = GET_WIDGET(builder, "button_panel"); - gtk_box_pack_end(GTK_BOX(buttons), *panel, FALSE, TRUE, 0); + gtk_box_pack_end(GTK_BOX(buttons), *panel, TRUE, TRUE, 0); /* Configure buttons */ for (i = 0; button_data[i].widget_name != NULL; i++) { @@ -833,32 +530,8 @@ load_mode(MathButtons *buttons, ButtonMode mode) if (button_data[i].tooltip) gtk_widget_set_tooltip_text(button, _(button_data[i].tooltip)); - - atk_object_set_name (gtk_widget_get_accessible (button), button_data[i].widget_name); - - switch (button_data[i].class) { - case NUMBER: - set_tint(button, &buttons->priv->color_numbers, 1); - break; - case NUMBER_BOLD: - set_tint(button, &buttons->priv->color_numbers, 2); - break; - case OPERATOR: - set_tint(button, &buttons->priv->color_operator, 1); - break; - case FUNCTION: - set_tint(button, &buttons->priv->color_function, 1); - break; - case MEMORY: - set_tint(button, &buttons->priv->color_memory, 1); - break; - case GROUP: - set_tint(button, &buttons->priv->color_group, 1); - break; - case ACTION: - set_tint(button, &buttons->priv->color_action, 2); - break; - } + + atk_object_set_name(gtk_widget_get_accessible(button), button_data[i].widget_name); } /* Set special button data */ @@ -868,16 +541,26 @@ load_mode(MathButtons *buttons, ButtonMode mode) name = g_strdup_printf("calc_%d_button", i); button = GET_WIDGET(builder, name); if (button) { + gchar buffer[7]; + gint len; + g_object_set_data(G_OBJECT(button), "calc_digit", GINT_TO_POINTER(i)); - set_tint(button, &buttons->priv->color_numbers, 1); - gtk_button_set_label(GTK_BUTTON(button), math_equation_get_digit_text(buttons->priv->equation, i)); + len = g_unichar_to_utf8(math_equation_get_digit_text(buttons->priv->equation, i), buffer); + buffer[len] = '\0'; + gtk_button_set_label(GTK_BUTTON(button), buffer); } g_free(name); } widget = GET_WIDGET(builder, "calc_numeric_point_button"); - if (widget) - gtk_button_set_label(GTK_BUTTON(widget), math_equation_get_numeric_point_text(buttons->priv->equation)); - + if (widget) { + MpSerializer *serializer = math_equation_get_serializer(buttons->priv->equation); + gchar buffer[7]; + gint len; + len = g_unichar_to_utf8(mp_serializer_get_radix(serializer), buffer); + buffer[len] = '\0'; + gtk_button_set_label(GTK_BUTTON(widget), buffer); + } + widget = GET_WIDGET(builder, "calc_superscript_button"); if (widget) { buttons->priv->superscript_toggles = g_list_append(buttons->priv->superscript_toggles, widget); @@ -891,37 +574,6 @@ load_mode(MathButtons *buttons, ButtonMode mode) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE); } - if (mode == ADVANCED) { - GtkListStore *model; - GtkTreeIter iter; - GtkCellRenderer *renderer; - - buttons->priv->angle_label = GET_WIDGET(builder, "angle_label"); - - buttons->priv->angle_combo = GET_WIDGET(builder, "angle_units_combo"); - model = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); - gtk_combo_box_set_model(GTK_COMBO_BOX(buttons->priv->angle_combo), GTK_TREE_MODEL(model)); - gtk_list_store_append(GTK_LIST_STORE(model), &iter); - gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, - /* Advanced buttons: Angle unit combo box: Use degrees for trigonometric calculations */ - _("Degrees"), 1, MP_DEGREES, -1); - gtk_list_store_append(GTK_LIST_STORE(model), &iter); - gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, - /* Advanced buttons: Angle unit combo box: Use radians for trigonometric calculations */ - _("Radians"), 1, MP_RADIANS, -1); - gtk_list_store_append(GTK_LIST_STORE(model), &iter); - gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, - /* Advanced buttons: Angle unit combo box: Use gradians for trigonometric calculations */ - _("Gradians"), 1, MP_GRADIANS, -1); - renderer = gtk_cell_renderer_text_new(); - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(buttons->priv->angle_combo), renderer, TRUE); - gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(buttons->priv->angle_combo), renderer, "text", 0); - - g_signal_connect(buttons->priv->angle_combo, "changed", G_CALLBACK(angle_unit_combobox_changed_cb), buttons); - g_signal_connect(buttons->priv->equation, "notify::angle-units", G_CALLBACK(angle_unit_cb), buttons); - angle_unit_cb(buttons->priv->equation, NULL, buttons); - } - if (mode == PROGRAMMING) { GtkListStore *model; GtkTreeIter iter; @@ -970,41 +622,8 @@ load_mode(MathButtons *buttons, ButtonMode mode) /* Setup financial functions */ if (mode == FINANCIAL) { - GtkListStore *model; - GtkCellRenderer *renderer; - load_finc_dialogs(buttons); - buttons->priv->source_currency_combo = GET_WIDGET(builder, "source_currency_combo"); - buttons->priv->target_currency_combo = GET_WIDGET(builder, "target_currency_combo"); - buttons->priv->currency_label = GET_WIDGET(builder, "currency_label"); - - model = gtk_list_store_new(1, G_TYPE_STRING); - - for (i = 0; currency_names[i].short_name != NULL; i++) { - GtkTreeIter iter; - - gtk_list_store_append(GTK_LIST_STORE(model), &iter); - gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, currency_names[i].short_name, -1); - } - - gtk_combo_box_set_model(GTK_COMBO_BOX(buttons->priv->source_currency_combo), GTK_TREE_MODEL(model)); - gtk_combo_box_set_model(GTK_COMBO_BOX(buttons->priv->target_currency_combo), GTK_TREE_MODEL(model)); - - renderer = gtk_cell_renderer_text_new(); - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(buttons->priv->source_currency_combo), renderer, TRUE); - gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(buttons->priv->source_currency_combo), renderer, "text", 0); - renderer = gtk_cell_renderer_text_new(); - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(buttons->priv->target_currency_combo), renderer, TRUE); - gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(buttons->priv->target_currency_combo), renderer, "text", 0); - - g_signal_connect(buttons->priv->source_currency_combo, "changed", G_CALLBACK(source_currency_combo_changed_cb), buttons); - g_signal_connect(buttons->priv->target_currency_combo, "changed", G_CALLBACK(target_currency_combo_changed_cb), buttons); - g_signal_connect(buttons->priv->equation, "notify::source-currency", G_CALLBACK(source_currency_changed_cb), buttons); - g_signal_connect(buttons->priv->equation, "notify::target-currency", G_CALLBACK(target_currency_changed_cb), buttons); - source_currency_changed_cb(buttons->priv->equation, NULL, buttons); - target_currency_changed_cb(buttons->priv->equation, NULL, buttons); - set_data(builder, "calc_finc_compounding_term_button", "finc_dialog", "ctrm_dialog"); set_data(builder, "calc_finc_double_declining_depreciation_button", "finc_dialog", "ddb_dialog"); set_data(builder, "calc_finc_future_value_button", "finc_dialog", "fv_dialog"); @@ -1020,11 +639,30 @@ load_mode(MathButtons *buttons, ButtonMode mode) gtk_builder_connect_signals(builder, buttons); display_changed_cb(buttons->priv->equation, NULL, buttons); - + return *panel; } +static void +converter_changed_cb(MathConverter *converter, MathButtons *buttons) +{ + Unit *from_unit, *to_unit; + + math_converter_get_conversion(converter, &from_unit, &to_unit); + if (buttons->priv->mode == FINANCIAL) { + math_equation_set_source_currency(buttons->priv->equation, unit_get_name(from_unit)); + math_equation_set_target_currency(buttons->priv->equation, unit_get_name(to_unit)); + } + else { + math_equation_set_source_units(buttons->priv->equation, unit_get_name(from_unit)); + math_equation_set_target_units(buttons->priv->equation, unit_get_name(to_unit)); + } + + g_object_unref(from_unit); + g_object_unref(to_unit); +} + static void load_buttons(MathButtons *buttons) @@ -1034,6 +672,12 @@ load_buttons(MathButtons *buttons) if (!gtk_widget_get_visible(GTK_WIDGET(buttons))) return; + if (!buttons->priv->converter) { + buttons->priv->converter = math_converter_new(buttons->priv->equation); + g_signal_connect(buttons->priv->converter, "changed", G_CALLBACK(converter_changed_cb), buttons); + gtk_box_pack_start(GTK_BOX(buttons), GTK_WIDGET(buttons->priv->converter), FALSE, TRUE, 0); + } + panel = load_mode(buttons, buttons->priv->mode); if (buttons->priv->active_panel == panel) return; @@ -1052,14 +696,13 @@ load_buttons(MathButtons *buttons) void math_buttons_set_mode(MathButtons *buttons, ButtonMode mode) { - ButtonMode old_mode; - + g_return_if_fail(buttons != NULL); + if (buttons->priv->mode == mode) return; - old_mode = buttons->priv->mode; buttons->priv->mode = mode; - + if (mode == PROGRAMMING) math_equation_set_base(buttons->priv->equation, buttons->priv->programming_base); else @@ -1067,6 +710,20 @@ math_buttons_set_mode(MathButtons *buttons, ButtonMode mode) load_buttons(buttons); + gtk_widget_set_visible(GTK_WIDGET(buttons->priv->converter), mode == ADVANCED || mode == FINANCIAL); + if (mode == ADVANCED) { + math_converter_set_category(buttons->priv->converter, NULL); + math_converter_set_conversion(buttons->priv->converter, + math_equation_get_source_units(buttons->priv->equation), + math_equation_get_target_units(buttons->priv->equation)); + } + else if (mode == FINANCIAL) { + math_converter_set_category(buttons->priv->converter, "currency"); + math_converter_set_conversion(buttons->priv->converter, + math_equation_get_source_currency(buttons->priv->equation), + math_equation_get_target_currency(buttons->priv->equation)); + } + g_object_notify(G_OBJECT(buttons), "mode"); } @@ -1081,13 +738,23 @@ math_buttons_get_mode(MathButtons *buttons) void math_buttons_set_programming_base(MathButtons *buttons, gint base) { + g_return_if_fail(buttons != NULL); + + if (base == buttons->priv->programming_base) + return; + buttons->priv->programming_base = base; + g_object_notify(G_OBJECT(buttons), "programming-base"); + + if (buttons->priv->mode == PROGRAMMING) + math_equation_set_base(buttons->priv->equation, base); } gint math_buttons_get_programming_base(MathButtons *buttons) { + g_return_val_if_fail(buttons != NULL, 10); return buttons->priv->programming_base; } @@ -1106,7 +773,7 @@ G_MODULE_EXPORT void subtract_cb(GtkWidget *widget, MathButtons *buttons) { - math_equation_insert_subtract(buttons->priv->equation); + math_equation_insert_subtract(buttons->priv->equation); } @@ -1170,7 +837,7 @@ button_menu_position_func(GtkMenu *menu, gint *x, gint *y, GtkAllocation allocation; GdkPoint loc; gint border; - + gdk_window_get_origin(gtk_widget_get_window(button), &loc.x, &loc.y); border = gtk_container_get_border_width(GTK_CONTAINER(button)); gtk_widget_get_allocation(button, &allocation); @@ -1187,161 +854,22 @@ popup_button_menu(GtkWidget *widget, GtkMenu *menu) } -static void -save_variable_cb(GtkWidget *widget, MathButtons *buttons) -{ - printf("save\n"); -} - - -static void -delete_variable_cb(GtkWidget *widget, MathButtons *buttons) -{ - printf("delete\n"); -} - - -static GtkWidget * -make_register_menu_item(MathButtons *buttons, const gchar *name, const MPNumber *value, gboolean can_modify, GCallback callback) -{ - gchar text[1024] = "", *mstr; - GtkWidget *item, *label; - - if (value) { - display_make_number(buttons->priv->equation, text, 1024, value); - mstr = g_strdup_printf("<span weight=\"bold\">%s</span> = %s", name, text); - } - else - mstr = g_strdup_printf("<span weight=\"bold\">%s</span>", name); - label = gtk_label_new(mstr); - gtk_label_set_use_markup(GTK_LABEL(label), TRUE); - gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); - g_free(mstr); - - item = gtk_menu_item_new(); - - // FIXME: Buttons don't work inside menus... - if (0) {//can_modify) { - GtkWidget *hbox, *button; - - hbox = gtk_hbox_new(FALSE, 6); - gtk_container_add(GTK_CONTAINER(item), hbox); - - gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); - - button = gtk_button_new(); - gtk_button_set_image(GTK_BUTTON(button), gtk_image_new_from_stock(GTK_STOCK_DELETE, GTK_ICON_SIZE_MENU)); - gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); - gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, TRUE, 0); - g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(delete_variable_cb), buttons); - - button = gtk_button_new(); - gtk_button_set_image(GTK_BUTTON(button), gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU)); - gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); - gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, TRUE, 0); - g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(save_variable_cb), buttons); - } - else - gtk_container_add(GTK_CONTAINER(item), label); - - g_object_set_data(G_OBJECT(item), "register_id", g_strdup(name)); // FIXME: Memory leak - g_signal_connect(item, "activate", callback, buttons); - - return item; -} - - -static void -store_menu_cb(GtkMenuItem *menu, MathButtons *buttons) -{ - math_equation_store(buttons->priv->equation, g_object_get_data(G_OBJECT(menu), "register_id")); -} - - -void store_cb(GtkWidget *widget, MathButtons *buttons); +void memory_cb(GtkWidget *widget, MathButtons *buttons); G_MODULE_EXPORT void -store_cb(GtkWidget *widget, MathButtons *buttons) +memory_cb(GtkWidget *widget, MathButtons *buttons) { - int i; - GtkWidget *menu; - GtkWidget *item; - gchar **names; - - menu = gtk_menu_new(); - gtk_menu_set_reserve_toggle_size(GTK_MENU(menu), FALSE); - set_tint(menu, &buttons->priv->color_memory, 1); - - names = math_variables_get_names(math_equation_get_variables(buttons->priv->equation)); - if (names[0] == NULL) { - item = gtk_menu_item_new_with_label(/* Text shown in store menu when no variables defined */ - _("No variables defined")); - gtk_widget_set_sensitive(item, FALSE); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); - } - for (i = 0; names[i]; i++) { - MPNumber *value; - value = math_variables_get_value(math_equation_get_variables(buttons->priv->equation), names[i]); - item = make_register_menu_item(buttons, names[i], value, TRUE, G_CALLBACK(store_menu_cb)); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); - } - - g_strfreev(names); - - // FIXME - //item = gtk_menu_item_new_with_label(_("Add variable")); - //gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); - - gtk_widget_show_all(menu); - popup_button_menu(widget, GTK_MENU(menu)); -} - - -static void -recall_menu_cb(GtkMenuItem *menu, MathButtons *buttons) -{ - math_equation_recall(buttons->priv->equation, g_object_get_data(G_OBJECT(menu), "register_id")); -} - - -void recall_cb(GtkWidget *widget, MathButtons *buttons); -G_MODULE_EXPORT -void -recall_cb(GtkWidget *widget, MathButtons *buttons) -{ - int i; - GtkWidget *menu; - GtkWidget *item; - gchar **names; - - menu = gtk_menu_new(); - gtk_menu_set_reserve_toggle_size(GTK_MENU(menu), FALSE); - set_tint(menu, &buttons->priv->color_memory, 1); - - names = math_variables_get_names(math_equation_get_variables(buttons->priv->equation)); - if (names[0] == NULL) { - item = gtk_menu_item_new_with_label(/* Text shown in recall menu when no variables defined */ - _("No variables defined")); - gtk_widget_set_sensitive(item, FALSE); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); - } - for (i = 0; names[i]; i++) { - MPNumber *value; - value = math_variables_get_value(math_equation_get_variables(buttons->priv->equation), names[i]); - item = make_register_menu_item(buttons, names[i], value, TRUE, G_CALLBACK(recall_menu_cb)); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); - } - - g_strfreev(names); + MathVariablePopup *popup; + GtkAllocation allocation; + gint x, y; - gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new()); - item = make_register_menu_item(buttons, "ans", math_equation_get_answer(buttons->priv->equation), FALSE, G_CALLBACK(recall_menu_cb)); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); - item = make_register_menu_item(buttons, "rand", NULL, FALSE, G_CALLBACK(recall_menu_cb)); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); + popup = math_variable_popup_new(buttons->priv->equation); + gtk_window_set_transient_for(GTK_WINDOW(popup), GTK_WINDOW(gtk_widget_get_toplevel(widget))); - gtk_widget_show_all(menu); - popup_button_menu(widget, GTK_MENU(menu)); + gtk_widget_get_allocation(widget, &allocation); + gdk_window_get_root_coords(gtk_widget_get_window(widget), allocation.x, allocation.y, &x, &y); + gtk_window_move(GTK_WINDOW(popup), x, y); + gtk_widget_show(GTK_WIDGET(popup)); } @@ -1356,7 +884,6 @@ shift_left_cb(GtkWidget *widget, MathButtons *buttons) menu = buttons->priv->shift_left_menu = gtk_menu_new(); gtk_menu_set_reserve_toggle_size(GTK_MENU(menu), FALSE); - set_tint(menu, &buttons->priv->color_action, 1); for (i = 1; i < 16; i++) { GtkWidget *item, *label; @@ -1400,7 +927,6 @@ shift_right_cb(GtkWidget *widget, MathButtons *buttons) menu = buttons->priv->shift_right_menu = gtk_menu_new(); gtk_menu_set_reserve_toggle_size(GTK_MENU(menu), FALSE); - set_tint(menu, &buttons->priv->color_action, 1); for (i = 1; i < 16; i++) { GtkWidget *item, *label; @@ -1429,7 +955,7 @@ shift_right_cb(GtkWidget *widget, MathButtons *buttons) } } - popup_button_menu(widget, GTK_MENU(buttons->priv->shift_right_menu)); + popup_button_menu(widget, GTK_MENU(buttons->priv->shift_right_menu)); } @@ -1448,10 +974,10 @@ function_cb(GtkWidget *widget, MathButtons *buttons) if (!buttons->priv->function_menu) { gint i; GtkWidget *menu; - struct + struct { gchar *name, *function; - } functions[] = + } functions[] = { { /* Tooltip for the integer component button */ N_("Integer Component"), "int " }, @@ -1470,20 +996,19 @@ function_cb(GtkWidget *widget, MathButtons *buttons) menu = buttons->priv->function_menu = gtk_menu_new(); gtk_menu_set_reserve_toggle_size(GTK_MENU(menu), FALSE); - set_tint(menu, &buttons->priv->color_function, 1); for (i = 0; functions[i].name != NULL; i++) { GtkWidget *item; - + item = gtk_menu_item_new_with_label(_(functions[i].name)); - g_object_set_data(G_OBJECT(item), "function", g_strdup (functions[i].function)); + g_object_set_data(G_OBJECT(item), "function", g_strdup(functions[i].function)); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); g_signal_connect(item, "activate", G_CALLBACK(insert_function_cb), buttons); gtk_widget_show(item); } } - popup_button_menu(widget, GTK_MENU(buttons->priv->function_menu)); + popup_button_menu(widget, GTK_MENU(buttons->priv->function_menu)); } @@ -1492,7 +1017,7 @@ G_MODULE_EXPORT void factorize_cb(GtkWidget *widget, MathButtons *buttons) { - math_equation_factorize (buttons->priv->equation); + math_equation_factorize(buttons->priv->equation); } @@ -1550,7 +1075,7 @@ finc_activate_cb(GtkWidget *widget, MathButtons *buttons) if (finc_dialog_fields[dialog][field+1] == NULL) { GtkWidget *dialog_widget; dialog_widget = gtk_widget_get_toplevel(widget); - if (gtk_widget_is_toplevel (dialog_widget)) { + if (gtk_widget_is_toplevel(dialog_widget)) { gtk_dialog_response(GTK_DIALOG(dialog_widget), GTK_RESPONSE_OK); return; @@ -1577,7 +1102,7 @@ finc_response_cb(GtkWidget *widget, gint response_id, MathButtons *buttons) if (response_id != GTK_RESPONSE_OK) return; - dialog = GPOINTER_TO_INT (g_object_get_data(G_OBJECT(widget), "finc_dialog")); + dialog = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "finc_dialog")); for (i = 0; i < 4; i++) { if (finc_dialog_fields[dialog][i] == NULL) { @@ -1602,7 +1127,7 @@ character_code_dialog_response_cb(GtkWidget *dialog, gint response_id, MathButto text = gtk_entry_get_text(GTK_ENTRY(buttons->priv->character_code_entry)); - if (response_id == GTK_RESPONSE_OK) { + if (response_id == GTK_RESPONSE_OK) { MPNumber x; int i = 0; @@ -1653,16 +1178,35 @@ bit_toggle_cb(GtkWidget *event_box, GdkEventButton *event, MathButtons *buttons) } +static void +remove_trailing_spaces(MathButtons *buttons) +{ + GtkTextMark *insert_mark; + GtkTextIter start, end; + insert_mark = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER(buttons->priv->equation)); + gtk_text_buffer_get_iter_at_mark(GTK_TEXT_BUFFER(buttons->priv->equation), &end, insert_mark); + start = end; + while (gtk_text_iter_backward_char(&start)) { + if (!g_unichar_isspace(gtk_text_iter_get_char(&start))) + break; + gtk_text_buffer_delete(GTK_TEXT_BUFFER(buttons->priv->equation), &start, &end); + } +} + void set_superscript_cb(GtkWidget *widget, MathButtons *buttons); G_MODULE_EXPORT void set_superscript_cb(GtkWidget *widget, MathButtons *buttons) { - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) - math_equation_set_number_mode(buttons->priv->equation, SUPERSCRIPT); + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { + math_equation_set_number_mode(buttons->priv->equation, SUPERSCRIPT); + if (!gtk_text_buffer_get_has_selection(GTK_TEXT_BUFFER(buttons->priv->equation))) { + remove_trailing_spaces(buttons); + } + } else if (math_equation_get_number_mode(buttons->priv->equation) == SUPERSCRIPT) - math_equation_set_number_mode(buttons->priv->equation, NORMAL); + math_equation_set_number_mode(buttons->priv->equation, NORMAL); } @@ -1671,10 +1215,14 @@ G_MODULE_EXPORT void set_subscript_cb(GtkWidget *widget, MathButtons *buttons) { - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) - math_equation_set_number_mode(buttons->priv->equation, SUBSCRIPT); + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { + math_equation_set_number_mode(buttons->priv->equation, SUBSCRIPT); + if (!gtk_text_buffer_get_has_selection(GTK_TEXT_BUFFER(buttons->priv->equation))) { + remove_trailing_spaces(buttons); + } + } else if (math_equation_get_number_mode(buttons->priv->equation) == SUBSCRIPT) - math_equation_set_number_mode(buttons->priv->equation, NORMAL); + math_equation_set_number_mode(buttons->priv->equation, NORMAL); } @@ -1683,7 +1231,7 @@ number_mode_changed_cb(MathEquation *equation, GParamSpec *spec, MathButtons *bu { GList *i; NumberMode mode; - + mode = math_equation_get_number_mode(equation); for (i = buttons->priv->superscript_toggles; i; i = i->next) { @@ -1698,18 +1246,18 @@ number_mode_changed_cb(MathEquation *equation, GParamSpec *spec, MathButtons *bu static void -math_buttons_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) +math_buttons_set_property(GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) { MathButtons *self; - self = MATH_BUTTONS (object); + self = MATH_BUTTONS(object); switch (prop_id) { case PROP_EQUATION: - self->priv->equation = g_value_get_object (value); + self->priv->equation = g_value_get_object(value); math_buttons_set_mode(self, self->priv->mode); g_signal_connect(self->priv->equation, "notify::display", G_CALLBACK(display_changed_cb), self); g_signal_connect(self->priv->equation, "notify::number-mode", G_CALLBACK(number_mode_changed_cb), self); @@ -1719,41 +1267,47 @@ math_buttons_set_property (GObject *object, display_changed_cb(self->priv->equation, NULL, self); break; case PROP_MODE: - math_buttons_set_mode(self, g_value_get_int (value)); + math_buttons_set_mode(self, g_value_get_int(value)); + break; + case PROP_PROGRAMMING_BASE: + math_buttons_set_programming_base(self, g_value_get_int(value)); break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; } } static void -math_buttons_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) +math_buttons_get_property(GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) { MathButtons *self; - self = MATH_BUTTONS (object); + self = MATH_BUTTONS(object); switch (prop_id) { case PROP_EQUATION: - g_value_set_object (value, self->priv->equation); + g_value_set_object(value, self->priv->equation); break; case PROP_MODE: - g_value_set_int (value, self->priv->mode); + g_value_set_int(value, self->priv->mode); + break; + case PROP_PROGRAMMING_BASE: + g_value_set_int(value, math_buttons_get_programming_base(self)); break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; } } static void -math_buttons_class_init (MathButtonsClass *klass) +math_buttons_class_init(MathButtonsClass *klass) { static GEnumValue button_mode_values[] = { @@ -1763,43 +1317,45 @@ math_buttons_class_init (MathButtonsClass *klass) {PROGRAMMING, "programming", "programming"}, {0, NULL, NULL} }; - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); object_class->get_property = math_buttons_get_property; object_class->set_property = math_buttons_set_property; - g_type_class_add_private (klass, sizeof (MathButtonsPrivate)); + g_type_class_add_private(klass, sizeof(MathButtonsPrivate)); button_mode_type = g_enum_register_static("ButtonMode", button_mode_values); - g_object_class_install_property (object_class, - PROP_EQUATION, - g_param_spec_object ("equation", - "equation", - "Equation being controlled", - math_equation_get_type(), - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - g_object_class_install_property (object_class, - PROP_MODE, - g_param_spec_enum ("mode", - "mode", - "Button mode", - button_mode_type, - BASIC, - G_PARAM_READWRITE)); + g_object_class_install_property(object_class, + PROP_EQUATION, + g_param_spec_object("equation", + "equation", + "Equation being controlled", + math_equation_get_type(), + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property(object_class, + PROP_MODE, + g_param_spec_enum("mode", + "mode", + "Button mode", + button_mode_type, + BASIC, + G_PARAM_READWRITE)); + g_object_class_install_property(object_class, + PROP_PROGRAMMING_BASE, + g_param_spec_int("programming-base", + "programming-base", + "Base to use in programming mode", + 2, 16, 10, + G_PARAM_READWRITE)); } static void -math_buttons_init (MathButtons *buttons) +math_buttons_init(MathButtons *buttons) { - buttons->priv = G_TYPE_INSTANCE_GET_PRIVATE (buttons, math_buttons_get_type(), MathButtonsPrivate); + buttons->priv = G_TYPE_INSTANCE_GET_PRIVATE(buttons, math_buttons_get_type(), MathButtonsPrivate); + gtk_box_set_spacing(GTK_BOX(buttons), 6); buttons->priv->programming_base = 10; - gdk_color_parse("#0000FF", &buttons->priv->color_numbers); - gdk_color_parse("#00FF00", &buttons->priv->color_action); - gdk_color_parse("#FF0000", &buttons->priv->color_operator); - gdk_color_parse("#00FFFF", &buttons->priv->color_function); - gdk_color_parse("#FF00FF", &buttons->priv->color_memory); - gdk_color_parse("#FFFFFF", &buttons->priv->color_group); g_signal_connect(G_OBJECT(buttons), "show", G_CALLBACK(load_buttons), NULL); } |