| File: | math-buttons.c |
| Warning: | line 477, column 9 Value stored to 'valid' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* |
| 2 | * Copyright (C) 2008-2011 Robert Ancell |
| 3 | * |
| 4 | * This program is free software: you can redistribute it and/or modify it under |
| 5 | * the terms of the GNU General Public License as published by the Free Software |
| 6 | * Foundation, either version 2 of the License, or (at your option) any later |
| 7 | * version. See http://www.gnu.org/copyleft/gpl.html the full text of the |
| 8 | * license. |
| 9 | */ |
| 10 | |
| 11 | #include <glib/gi18n.h> |
| 12 | |
| 13 | #include "math-buttons.h" |
| 14 | #include "math-converter.h" |
| 15 | #include "math-variable-popup.h" |
| 16 | #include "financial.h" |
| 17 | #include "mp-serializer.h" |
| 18 | #include "utility.h" |
| 19 | |
| 20 | enum { |
| 21 | PROP_0, |
| 22 | PROP_EQUATION, |
| 23 | PROP_MODE, |
| 24 | PROP_PROGRAMMING_BASE |
| 25 | }; |
| 26 | |
| 27 | static GType button_mode_type; |
| 28 | |
| 29 | #define MAXBITS64 64 /* Bit panel: number of bit fields. */ |
| 30 | |
| 31 | struct MathButtonsPrivate |
| 32 | { |
| 33 | MathEquation *equation; |
| 34 | |
| 35 | ButtonMode mode; |
| 36 | gint programming_base; |
| 37 | |
| 38 | MathConverter *converter; |
| 39 | |
| 40 | CtkBuilder *basic_ui, *advanced_ui, *financial_ui, *programming_ui; |
| 41 | |
| 42 | CtkWidget *bas_panel, *adv_panel, *fin_panel, *prog_panel; |
| 43 | CtkWidget *active_panel; |
| 44 | |
| 45 | CtkWidget *shift_left_menu, *shift_right_menu; |
| 46 | |
| 47 | CtkWidget *function_menu; |
| 48 | CtkWidget *const_menu; |
| 49 | |
| 50 | GList *superscript_toggles; |
| 51 | GList *subscript_toggles; |
| 52 | |
| 53 | CtkWidget *base_combo; |
| 54 | CtkWidget *base_label; |
| 55 | CtkWidget *bit_panel; |
| 56 | CtkWidget *bit_labels[MAXBITS64]; |
| 57 | |
| 58 | CtkWidget *character_code_dialog; |
| 59 | CtkWidget *character_code_entry; |
| 60 | }; |
| 61 | |
| 62 | G_DEFINE_TYPE_WITH_PRIVATE (MathButtons, math_buttons, CTK_TYPE_BOX)static void math_buttons_init (MathButtons *self); static void math_buttons_class_init (MathButtonsClass *klass); static GType math_buttons_get_type_once (void); static gpointer math_buttons_parent_class = ((void*)0); static gint MathButtons_private_offset; static void math_buttons_class_intern_init (gpointer klass) { math_buttons_parent_class = g_type_class_peek_parent (klass); if (MathButtons_private_offset != 0) g_type_class_adjust_private_offset (klass, &MathButtons_private_offset ); math_buttons_class_init ((MathButtonsClass*) klass); } __attribute__ ((__unused__)) static inline gpointer math_buttons_get_instance_private (MathButtons *self) { return (((gpointer) ((guint8*) (self) + (glong) (MathButtons_private_offset)))); } GType math_buttons_get_type (void) { static GType static_g_define_type_id = 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer), "Expression evaluates to false"); (void) ( 0 ? (gpointer) * (&static_g_define_type_id) : ((void*)0)) ; (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (*(&static_g_define_type_id)) gapg_temp_newval; __typeof__ ((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id ); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5) ; gapg_temp_newval; })) && g_once_init_enter_pointer ( &static_g_define_type_id)); })) ) { GType g_define_type_id = math_buttons_get_type_once (); (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer) , "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id ) = (g_define_type_id)) : (void) 0; g_once_init_leave_pointer ((&static_g_define_type_id), (gpointer) (guintptr) (g_define_type_id )); })) ; } return static_g_define_type_id; } __attribute__ ( (__noinline__)) static GType math_buttons_get_type_once (void ) { GType g_define_type_id = g_type_register_static_simple (( ctk_box_get_type ()), g_intern_static_string ("MathButtons"), sizeof (MathButtonsClass), (GClassInitFunc)(void (*)(void)) math_buttons_class_intern_init , sizeof (MathButtons), (GInstanceInitFunc)(void (*)(void)) math_buttons_init , (GTypeFlags) 0); { {{ MathButtons_private_offset = g_type_add_instance_private (g_define_type_id, sizeof (MathButtonsPrivate)); };} } return g_define_type_id; }; |
| 63 | |
| 64 | #define UI_BASIC_RESOURCE_PATH"/org/cafe/calculator/ui/buttons-basic.ui" "/org/cafe/calculator/ui/buttons-basic.ui" |
| 65 | #define UI_ADVANCED_RESOURCE_PATH"/org/cafe/calculator/ui/buttons-advanced.ui" "/org/cafe/calculator/ui/buttons-advanced.ui" |
| 66 | #define UI_FINANCIAL_RESOURCE_PATH"/org/cafe/calculator/ui/buttons-financial.ui" "/org/cafe/calculator/ui/buttons-financial.ui" |
| 67 | #define UI_PROGRAMMING_RESOURCE_PATH"/org/cafe/calculator/ui/buttons-programming.ui" "/org/cafe/calculator/ui/buttons-programming.ui" |
| 68 | |
| 69 | #define GET_WIDGET(ui, name)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object((ui), (name)))), ((ctk_widget_get_type ())))))) \ |
| 70 | CTK_WIDGET(ctk_builder_get_object((ui), (name)))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object((ui), (name)))), ((ctk_widget_get_type ())))))) |
| 71 | |
| 72 | #define WM_WIDTH_FACTOR10 10 |
| 73 | #define WM_HEIGHT_FACTOR30 30 |
| 74 | |
| 75 | typedef enum |
| 76 | { |
| 77 | NUMBER, |
| 78 | NUMBER_BOLD, |
| 79 | OPERATOR, |
| 80 | FUNCTION, |
| 81 | MEMORY, |
| 82 | GROUP, |
| 83 | ACTION |
| 84 | } ButtonClass; |
| 85 | |
| 86 | typedef struct { |
| 87 | const char *widget_name; |
| 88 | const char *data; |
| 89 | ButtonClass class; |
| 90 | const char *tooltip; |
| 91 | } ButtonData; |
| 92 | |
| 93 | static ButtonData button_data[] = { |
| 94 | {"pi", "π", NUMBER, |
| 95 | /* Tooltip for the Pi button */ |
| 96 | N_("Pi [Ctrl+P]")("Pi [Ctrl+P]")}, |
| 97 | {"eulers_number", "e", NUMBER, |
| 98 | /* Tooltip for the Euler's Number button */ |
| 99 | N_("Euler’s Number")("Euler’s Number")}, |
| 100 | {"imaginary", "i", NUMBER, NULL((void*)0)}, |
| 101 | {"numeric_point", NULL((void*)0), NUMBER, NULL((void*)0)}, |
| 102 | {"subscript", NULL((void*)0), NUMBER_BOLD, |
| 103 | /* Tooltip for the subscript button */ |
| 104 | N_("Subscript mode [Alt]")("Subscript mode [Alt]")}, |
| 105 | {"superscript", NULL((void*)0), NUMBER_BOLD, |
| 106 | /* Tooltip for the superscript button */ |
| 107 | N_("Superscript mode [Ctrl]")("Superscript mode [Ctrl]")}, |
| 108 | {"exponential", NULL((void*)0), NUMBER_BOLD, |
| 109 | /* Tooltip for the scientific exponent button */ |
| 110 | N_("Scientific exponent [Ctrl+E]")("Scientific exponent [Ctrl+E]")}, |
| 111 | {"add", "+", OPERATOR, |
| 112 | /* Tooltip for the add button */ |
| 113 | N_("Add [+]")("Add [+]")}, |
| 114 | {"subtract", "−", OPERATOR, |
| 115 | /* Tooltip for the subtract button */ |
| 116 | N_("Subtract [-]")("Subtract [-]")}, |
| 117 | {"multiply", "×", OPERATOR, |
| 118 | /* Tooltip for the multiply button */ |
| 119 | N_("Multiply [*]")("Multiply [*]")}, |
| 120 | {"divide", "÷", OPERATOR, |
| 121 | /* Tooltip for the divide button */ |
| 122 | N_("Divide [/]")("Divide [/]")}, |
| 123 | {"modulus_divide", " mod ", OPERATOR, |
| 124 | /* Tooltip for the modulus divide button */ |
| 125 | N_("Modulus divide")("Modulus divide")}, |
| 126 | {"function", NULL((void*)0), FUNCTION, |
| 127 | /* Tooltip for the additional functions button */ |
| 128 | N_("Additional Functions")("Additional Functions")}, |
| 129 | {"const", NULL((void*)0), FUNCTION, |
| 130 | /* Tooltip for the additional constant button */ |
| 131 | N_("Additional constants")("Additional constants")}, |
| 132 | {"x_pow_y", "^", FUNCTION, |
| 133 | /* Tooltip for the exponent button */ |
| 134 | N_("Exponent [^ or **]")("Exponent [^ or **]")}, |
| 135 | {"x_squared", "²", FUNCTION, |
| 136 | /* Tooltip for the square button */ |
| 137 | N_("Square [Ctrl+2]")("Square [Ctrl+2]")}, |
| 138 | {"percentage", "%", NUMBER, |
| 139 | /* Tooltip for the percentage button */ |
| 140 | N_("Percentage [%]")("Percentage [%]")}, |
| 141 | {"factorial", "!", FUNCTION, |
| 142 | /* Tooltip for the factorial button */ |
| 143 | N_("Factorial [!]")("Factorial [!]")}, |
| 144 | {"abs", "|", FUNCTION, |
| 145 | /* Tooltip for the absolute value button */ |
| 146 | N_("Absolute value [|]")("Absolute value [|]")}, |
| 147 | {"arg", "Arg ", FUNCTION, |
| 148 | /* Tooltip for the complex argument component button */ |
| 149 | N_("Complex argument")("Complex argument")}, |
| 150 | {"conjugate", "conj ", FUNCTION, |
| 151 | /* Tooltip for the complex conjugate button */ |
| 152 | N_("Complex conjugate")("Complex conjugate")}, |
| 153 | {"root", "√", FUNCTION, |
| 154 | /* Tooltip for the root button */ |
| 155 | N_("Root [Ctrl+R]")("Root [Ctrl+R]")}, |
| 156 | {"square_root", "√", FUNCTION, |
| 157 | /* Tooltip for the square root button */ |
| 158 | N_("Square root [Ctrl+R]")("Square root [Ctrl+R]")}, |
| 159 | {"logarithm", "log ", FUNCTION, |
| 160 | /* Tooltip for the logarithm button */ |
| 161 | N_("Logarithm")("Logarithm")}, |
| 162 | {"natural_logarithm", "ln ", FUNCTION, |
| 163 | /* Tooltip for the natural logarithm button */ |
| 164 | N_("Natural Logarithm")("Natural Logarithm")}, |
| 165 | {"sine", "sin ", FUNCTION, |
| 166 | /* Tooltip for the sine button */ |
| 167 | N_("Sine")("Sine")}, |
| 168 | {"cosine", "cos ", FUNCTION, |
| 169 | /* Tooltip for the cosine button */ |
| 170 | N_("Cosine")("Cosine")}, |
| 171 | {"tangent", "tan ", FUNCTION, |
| 172 | /* Tooltip for the tangent button */ |
| 173 | N_("Tangent")("Tangent")}, |
| 174 | {"hyperbolic_sine", "sinh ", FUNCTION, |
| 175 | /* Tooltip for the hyperbolic sine button */ |
| 176 | N_("Hyperbolic Sine")("Hyperbolic Sine")}, |
| 177 | {"hyperbolic_cosine", "cosh ", FUNCTION, |
| 178 | /* Tooltip for the hyperbolic cosine button */ |
| 179 | N_("Hyperbolic Cosine")("Hyperbolic Cosine")}, |
| 180 | {"hyperbolic_tangent", "tanh ", FUNCTION, |
| 181 | /* Tooltip for the hyperbolic tangent button */ |
| 182 | N_("Hyperbolic Tangent")("Hyperbolic Tangent")}, |
| 183 | {"inverse_sine", "asin ", FUNCTION, |
| 184 | /* Tooltip for the inverse sine button */ |
| 185 | N_("Inverse Sine")("Inverse Sine")}, |
| 186 | {"inverse_cosine", "acos ", FUNCTION, |
| 187 | /* Tooltip for the inverse cosine button */ |
| 188 | N_("Inverse Cosine")("Inverse Cosine")}, |
| 189 | {"inverse_tangent", "atan ", FUNCTION, |
| 190 | /* Tooltip for the inverse tangent button */ |
| 191 | N_("Inverse Tangent")("Inverse Tangent")}, |
| 192 | {"inverse", "⁻¹", FUNCTION, |
| 193 | /* Tooltip for the inverse button */ |
| 194 | N_("Inverse [Ctrl+I]")("Inverse [Ctrl+I]")}, |
| 195 | {"and", "∧", OPERATOR, |
| 196 | /* Tooltip for the boolean AND button */ |
| 197 | N_("Boolean AND")("Boolean AND")}, |
| 198 | {"or", "∨", OPERATOR, |
| 199 | /* Tooltip for the boolean OR button */ |
| 200 | N_("Boolean OR")("Boolean OR")}, |
| 201 | {"xor", "⊻", OPERATOR, |
| 202 | /* Tooltip for the exclusive OR button */ |
| 203 | N_("Boolean Exclusive OR")("Boolean Exclusive OR")}, |
| 204 | {"not", "¬", FUNCTION, |
| 205 | /* Tooltip for the boolean NOT button */ |
| 206 | N_("Boolean NOT")("Boolean NOT")}, |
| 207 | {"integer_portion", "int ", FUNCTION, |
| 208 | /* Tooltip for the integer component button */ |
| 209 | N_("Integer Component")("Integer Component")}, |
| 210 | {"fractional_portion", "frac ", FUNCTION, |
| 211 | /* Tooltip for the fractional component button */ |
| 212 | N_("Fractional Component")("Fractional Component")}, |
| 213 | {"real_portion", "Re ", FUNCTION, |
| 214 | /* Tooltip for the real component button */ |
| 215 | N_("Real Component")("Real Component")}, |
| 216 | {"imaginary_portion", "Im ", FUNCTION, |
| 217 | /* Tooltip for the imaginary component button */ |
| 218 | N_("Imaginary Component")("Imaginary Component")}, |
| 219 | {"ones_complement", "ones ", FUNCTION, |
| 220 | /* Tooltip for the ones' complement button */ |
| 221 | N_("Ones' Complement")("Ones' Complement")}, |
| 222 | {"twos_complement", "twos ", FUNCTION, |
| 223 | /* Tooltip for the two's complement button */ |
| 224 | N_("Two's Complement")("Two's Complement")}, |
| 225 | {"trunc", "trunc ", FUNCTION, |
| 226 | /* Tooltip for the truncate button */ |
| 227 | N_("Truncate")("Truncate")}, |
| 228 | {"start_group", "(", GROUP, |
| 229 | /* Tooltip for the start group button */ |
| 230 | N_("Start Group [(]")("Start Group [(]")}, |
| 231 | {"end_group", ")", GROUP, |
| 232 | /* Tooltip for the end group button */ |
| 233 | N_("End Group [)]")("End Group [)]")}, |
| 234 | {"memory", NULL((void*)0), MEMORY, |
| 235 | /* Tooltip for the memory button */ |
| 236 | N_("Memory")("Memory")}, |
| 237 | {"character", NULL((void*)0), MEMORY, |
| 238 | /* Tooltip for the insert character code button */ |
| 239 | N_("Insert Character Code")("Insert Character Code")}, |
| 240 | {"result", NULL((void*)0), ACTION, |
| 241 | /* Tooltip for the solve button */ |
| 242 | N_("Calculate Result")("Calculate Result")}, |
| 243 | {"factor", NULL((void*)0), ACTION, |
| 244 | /* Tooltip for the factor button */ |
| 245 | N_("Factorize [Ctrl+F]")("Factorize [Ctrl+F]")}, |
| 246 | {"clear", NULL((void*)0), GROUP, |
| 247 | /* Tooltip for the clear button */ |
| 248 | N_("Clear Display [Escape]")("Clear Display [Escape]")}, |
| 249 | {"undo", NULL((void*)0), GROUP, |
| 250 | /* Tooltip for the undo button */ |
| 251 | N_("Undo [Ctrl+Z]")("Undo [Ctrl+Z]")}, |
| 252 | {"shift_left", NULL((void*)0), ACTION, |
| 253 | /* Tooltip for the shift left button */ |
| 254 | N_("Shift Left [<<]")("Shift Left [<<]")}, |
| 255 | {"shift_right", NULL((void*)0), ACTION, |
| 256 | /* Tooltip for the shift right button */ |
| 257 | N_("Shift Right [>>]")("Shift Right [>>]")}, |
| 258 | {"finc_compounding_term", NULL((void*)0), FUNCTION, |
| 259 | /* Tooltip for the compounding term button */ |
| 260 | N_("Compounding Term")("Compounding Term")}, |
| 261 | {"finc_double_declining_depreciation", NULL((void*)0), FUNCTION, |
| 262 | /* Tooltip for the double declining depreciation button */ |
| 263 | N_("Double Declining Depreciation")("Double Declining Depreciation")}, |
| 264 | {"finc_future_value", NULL((void*)0), FUNCTION, |
| 265 | /* Tooltip for the future value button */ |
| 266 | N_("Future Value")("Future Value")}, |
| 267 | {"finc_term", NULL((void*)0), FUNCTION, |
| 268 | /* Tooltip for the financial term button */ |
| 269 | N_("Financial Term")("Financial Term")}, |
| 270 | {"finc_sum_of_the_years_digits_depreciation", NULL((void*)0), FUNCTION, |
| 271 | /* Tooltip for the sum of the years digits depreciation button */ |
| 272 | N_("Sum of the Years Digits Depreciation")("Sum of the Years Digits Depreciation")}, |
| 273 | {"finc_straight_line_depreciation", NULL((void*)0), FUNCTION, |
| 274 | /* Tooltip for the straight line depreciation button */ |
| 275 | N_("Straight Line Depreciation")("Straight Line Depreciation")}, |
| 276 | {"finc_periodic_interest_rate", NULL((void*)0), FUNCTION, |
| 277 | /* Tooltip for the periodic interest rate button */ |
| 278 | N_("Periodic Interest Rate")("Periodic Interest Rate")}, |
| 279 | {"finc_present_value", NULL((void*)0), FUNCTION, |
| 280 | /* Tooltip for the present value button */ |
| 281 | N_("Present Value")("Present Value")}, |
| 282 | {"finc_periodic_payment", NULL((void*)0), FUNCTION, |
| 283 | /* Tooltip for the periodic payment button */ |
| 284 | N_("Periodic Payment")("Periodic Payment")}, |
| 285 | {"finc_gross_profit_margin", NULL((void*)0), FUNCTION, |
| 286 | /* Tooltip for the gross profit margin button */ |
| 287 | N_("Gross Profit Margin")("Gross Profit Margin")}, |
| 288 | {NULL((void*)0), NULL((void*)0), 0, NULL((void*)0)} |
| 289 | }; |
| 290 | |
| 291 | /* The names of each field in the dialogs for the financial functions */ |
| 292 | static char *finc_dialog_fields[][5] = { |
| 293 | {"ctrm_pint", "ctrm_fv", "ctrm_pv", NULL((void*)0), NULL((void*)0)}, |
| 294 | {"ddb_cost", "ddb_life", "ddb_period", NULL((void*)0), NULL((void*)0)}, |
| 295 | {"fv_pmt", "fv_pint", "fv_n", NULL((void*)0), NULL((void*)0)}, |
| 296 | {"gpm_cost", "gpm_margin", NULL((void*)0), NULL((void*)0), NULL((void*)0)}, |
| 297 | {"pmt_prin", "pmt_pint", "pmt_n", NULL((void*)0), NULL((void*)0)}, |
| 298 | {"pv_pmt", "pv_pint", "pv_n", NULL((void*)0), NULL((void*)0)}, |
| 299 | {"rate_fv", "rate_pv", "rate_n", NULL((void*)0), NULL((void*)0)}, |
| 300 | {"sln_cost", "sln_salvage", "sln_life", NULL((void*)0), NULL((void*)0)}, |
| 301 | {"syd_cost", "syd_salvage", "syd_life", "syd_period", NULL((void*)0)}, |
| 302 | {"term_pmt", "term_fv", "term_pint", NULL((void*)0), NULL((void*)0)}, |
| 303 | {NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0)} |
| 304 | }; |
| 305 | |
| 306 | |
| 307 | MathButtons * |
| 308 | math_buttons_new(MathEquation *equation) |
| 309 | { |
| 310 | return g_object_new(math_buttons_get_type(), "equation", equation, NULL((void*)0)); |
| 311 | } |
| 312 | |
| 313 | static void |
| 314 | set_data(CtkBuilder *ui, const gchar *object_name, const gchar *name, const char *value) |
| 315 | { |
| 316 | GObject *object; |
| 317 | object = ctk_builder_get_object(ui, object_name); |
| 318 | if (object) |
| 319 | g_object_set_data(object, name, GINT_TO_POINTER(value)((gpointer) (glong) (value))); |
| 320 | } |
| 321 | |
| 322 | |
| 323 | static void |
| 324 | set_int_data(CtkBuilder *ui, const gchar *object_name, const gchar *name, gint value) |
| 325 | { |
| 326 | GObject *object; |
| 327 | object = ctk_builder_get_object(ui, object_name); |
| 328 | if (object) |
| 329 | g_object_set_data(object, name, GINT_TO_POINTER(value)((gpointer) (glong) (value))); |
| 330 | } |
| 331 | |
| 332 | |
| 333 | static void |
| 334 | load_finc_dialogs(MathButtons *buttons) |
| 335 | { |
| 336 | int i, j; |
| 337 | |
| 338 | set_int_data(buttons->priv->financial_ui, "ctrm_dialog", "finc_dialog", FINC_CTRM_DIALOG); |
| 339 | set_int_data(buttons->priv->financial_ui, "ddb_dialog", "finc_dialog", FINC_DDB_DIALOG); |
| 340 | set_int_data(buttons->priv->financial_ui, "fv_dialog", "finc_dialog", FINC_FV_DIALOG); |
| 341 | set_int_data(buttons->priv->financial_ui, "gpm_dialog", "finc_dialog", FINC_GPM_DIALOG); |
| 342 | set_int_data(buttons->priv->financial_ui, "pmt_dialog", "finc_dialog", FINC_PMT_DIALOG); |
| 343 | set_int_data(buttons->priv->financial_ui, "pv_dialog", "finc_dialog", FINC_PV_DIALOG); |
| 344 | set_int_data(buttons->priv->financial_ui, "rate_dialog", "finc_dialog", FINC_RATE_DIALOG); |
| 345 | set_int_data(buttons->priv->financial_ui, "sln_dialog", "finc_dialog", FINC_SLN_DIALOG); |
| 346 | set_int_data(buttons->priv->financial_ui, "syd_dialog", "finc_dialog", FINC_SYD_DIALOG); |
| 347 | set_int_data(buttons->priv->financial_ui, "term_dialog", "finc_dialog", FINC_TERM_DIALOG); |
| 348 | |
| 349 | for (i = 0; finc_dialog_fields[i][0] != NULL((void*)0); i++) { |
| 350 | for (j = 0; finc_dialog_fields[i][j]; j++) { |
| 351 | GObject *o; |
| 352 | o = ctk_builder_get_object (buttons->priv->financial_ui, finc_dialog_fields[i][j]); |
| 353 | g_object_set_data(o, "finc_field", GINT_TO_POINTER(j)((gpointer) (glong) (j))); |
| 354 | g_object_set_data(o, "finc_dialog", GINT_TO_POINTER(i)((gpointer) (glong) (i))); |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | |
| 360 | static void |
| 361 | update_bit_panel(MathButtons *buttons) |
| 362 | { |
| 363 | MPNumber x; |
| 364 | gboolean enabled; |
| 365 | guint64 bits; |
| 366 | int i; |
| 367 | GString *label; |
| 368 | gint base; |
| 369 | |
| 370 | if (!buttons->priv->bit_panel) |
| 371 | return; |
| 372 | |
| 373 | enabled = math_equation_get_number(buttons->priv->equation, &x); |
| 374 | |
| 375 | if (enabled) { |
| 376 | MPNumber max, fraction; |
| 377 | |
| 378 | mp_set_from_unsigned_integer(G_MAXUINT64(0xffffffffffffffffUL), &max); |
| 379 | mp_fractional_part(&x, &fraction); |
| 380 | if (mp_is_negative(&x) || mp_is_greater_than(&x, &max) || !mp_is_zero(&fraction)) |
| 381 | enabled = FALSE(0); |
| 382 | else |
| 383 | bits = mp_cast_to_unsigned_int(&x); |
| 384 | } |
| 385 | |
| 386 | ctk_widget_set_sensitive(buttons->priv->bit_panel, enabled); |
| 387 | ctk_widget_set_sensitive(buttons->priv->base_label, enabled); |
| 388 | |
| 389 | if (!enabled) |
| 390 | return; |
| 391 | |
| 392 | for (i = 0; i < MAXBITS64; i++) { |
| 393 | const gchar *label; |
| 394 | |
| 395 | if (bits & (1LLU << (MAXBITS64-i-1))) |
| 396 | label = " 1"; |
| 397 | else |
| 398 | label = " 0"; |
| 399 | ctk_label_set_text(CTK_LABEL(buttons->priv->bit_labels[i])((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons->priv->bit_labels[i])), ((ctk_label_get_type ())))))), label); |
| 400 | } |
| 401 | |
| 402 | base = math_equation_get_base(buttons->priv->equation); |
| 403 | label = g_string_new(""); |
| 404 | if (base != 8) { |
| 405 | if (label->len != 0) |
| 406 | g_string_append(label, " = ")(__builtin_constant_p (" = ") ? __extension__ ({ const char * const __val = (" = "); g_string_append_len_inline (label, __val , (__val != ((void*)0)) ? (gssize) strlen (((__val) + !(__val ))) : (gssize) -1); }) : g_string_append_len_inline (label, " = " , (gssize) -1)); |
| 407 | g_string_append_printf(label, "%" G_GINT64_MODIFIER"l" "o", bits); |
| 408 | g_string_append(label, "₈")(__builtin_constant_p ("₈") ? __extension__ ({ const char * const __val = ("₈"); g_string_append_len_inline (label, __val , (__val != ((void*)0)) ? (gssize) strlen (((__val) + !(__val ))) : (gssize) -1); }) : g_string_append_len_inline (label, "₈" , (gssize) -1)); |
| 409 | } |
| 410 | if (base != 10) { |
| 411 | if (label->len != 0) |
| 412 | g_string_append(label, " = ")(__builtin_constant_p (" = ") ? __extension__ ({ const char * const __val = (" = "); g_string_append_len_inline (label, __val , (__val != ((void*)0)) ? (gssize) strlen (((__val) + !(__val ))) : (gssize) -1); }) : g_string_append_len_inline (label, " = " , (gssize) -1)); |
| 413 | g_string_append_printf(label, "%" G_GINT64_MODIFIER"l" "u", bits); |
| 414 | g_string_append(label, "₁₀")(__builtin_constant_p ("₁₀") ? __extension__ ({ const char * const __val = ("₁₀"); g_string_append_len_inline (label , __val, (__val != ((void*)0)) ? (gssize) strlen (((__val) + ! (__val))) : (gssize) -1); }) : g_string_append_len_inline (label , "₁₀", (gssize) -1)); |
| 415 | } |
| 416 | if (base != 16) { |
| 417 | if (label->len != 0) |
| 418 | g_string_append(label, " = ")(__builtin_constant_p (" = ") ? __extension__ ({ const char * const __val = (" = "); g_string_append_len_inline (label, __val , (__val != ((void*)0)) ? (gssize) strlen (((__val) + !(__val ))) : (gssize) -1); }) : g_string_append_len_inline (label, " = " , (gssize) -1)); |
| 419 | g_string_append_printf(label, "%" G_GINT64_MODIFIER"l" "X", bits); |
| 420 | g_string_append(label, "₁₆")(__builtin_constant_p ("₁₆") ? __extension__ ({ const char * const __val = ("₁₆"); g_string_append_len_inline (label , __val, (__val != ((void*)0)) ? (gssize) strlen (((__val) + ! (__val))) : (gssize) -1); }) : g_string_append_len_inline (label , "₁₆", (gssize) -1)); |
| 421 | } |
| 422 | |
| 423 | ctk_label_set_text(CTK_LABEL(buttons->priv->base_label)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons->priv->base_label)), ((ctk_label_get_type ( ))))))), label->str); |
| 424 | g_string_free(label, TRUE)(__builtin_constant_p ((!(0))) ? (((!(0))) ? (g_string_free) ( (label), ((!(0)))) : g_string_free_and_steal (label)) : (g_string_free ) ((label), ((!(0))))); |
| 425 | } |
| 426 | |
| 427 | |
| 428 | static void |
| 429 | display_changed_cb (MathEquation *equation G_GNUC_UNUSED__attribute__ ((__unused__)), |
| 430 | GParamSpec *spec G_GNUC_UNUSED__attribute__ ((__unused__)), |
| 431 | MathButtons *buttons) |
| 432 | { |
| 433 | update_bit_panel(buttons); |
| 434 | } |
| 435 | |
| 436 | |
| 437 | static void |
| 438 | base_combobox_changed_cb(CtkWidget *combo, MathButtons *buttons) |
| 439 | { |
| 440 | gint value; |
| 441 | CtkTreeModel *model; |
| 442 | CtkTreeIter iter; |
| 443 | |
| 444 | model = ctk_combo_box_get_model(CTK_COMBO_BOX(combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((combo)), ((ctk_combo_box_get_type ()))))))); |
| 445 | ctk_combo_box_get_active_iter(CTK_COMBO_BOX(combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((combo)), ((ctk_combo_box_get_type ())))))), &iter); |
| 446 | ctk_tree_model_get(model, &iter, 1, &value, -1); |
| 447 | |
| 448 | math_buttons_set_programming_base(buttons, value); |
| 449 | } |
| 450 | |
| 451 | |
| 452 | static void |
| 453 | base_changed_cb (MathEquation *equation G_GNUC_UNUSED__attribute__ ((__unused__)), |
| 454 | GParamSpec *spec G_GNUC_UNUSED__attribute__ ((__unused__)), |
| 455 | MathButtons *buttons) |
| 456 | { |
| 457 | CtkTreeModel *model; |
| 458 | CtkTreeIter iter; |
| 459 | gboolean valid; |
| 460 | |
| 461 | if (buttons->priv->mode != PROGRAMMING) |
| 462 | return; |
| 463 | |
| 464 | model = ctk_combo_box_get_model(CTK_COMBO_BOX(buttons->priv->base_combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons->priv->base_combo)), ((ctk_combo_box_get_type ()))))))); |
| 465 | valid = ctk_tree_model_get_iter_first(model, &iter); |
| 466 | buttons->priv->programming_base = math_equation_get_base(buttons->priv->equation); |
| 467 | |
| 468 | while (valid) { |
| 469 | gint v; |
| 470 | |
| 471 | ctk_tree_model_get(model, &iter, 1, &v, -1); |
| 472 | if (v == buttons->priv->programming_base) |
| 473 | break; |
| 474 | valid = ctk_tree_model_iter_next(model, &iter); |
| 475 | } |
| 476 | if (!valid) |
| 477 | valid = ctk_tree_model_get_iter_first(model, &iter); |
Value stored to 'valid' is never read | |
| 478 | |
| 479 | ctk_combo_box_set_active_iter(CTK_COMBO_BOX(buttons->priv->base_combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons->priv->base_combo)), ((ctk_combo_box_get_type ())))))), &iter); |
| 480 | } |
| 481 | |
| 482 | |
| 483 | static CtkWidget * |
| 484 | load_mode(MathButtons *buttons, ButtonMode mode) |
| 485 | { |
| 486 | CtkBuilder *builder, **builder_ptr; |
| 487 | gint i; |
| 488 | gchar *name; |
| 489 | const gchar *path; |
| 490 | static gchar *objects[] = { "button_panel", "character_code_dialog", "currency_dialog", |
| 491 | "ctrm_dialog", "ddb_dialog", "fv_dialog", "gpm_dialog", |
| 492 | "pmt_dialog", "pv_dialog", "rate_dialog", "sln_dialog", |
| 493 | "syd_dialog", "term_dialog", "adjustment1", "adjustment2", NULL((void*)0) }; |
| 494 | CtkWidget *widget, **panel; |
| 495 | GError *error = NULL((void*)0); |
| 496 | |
| 497 | switch (mode) { |
| 498 | default: |
| 499 | case BASIC: |
| 500 | builder_ptr = &buttons->priv->basic_ui; |
| 501 | path = UI_BASIC_RESOURCE_PATH"/org/cafe/calculator/ui/buttons-basic.ui"; |
| 502 | panel = &buttons->priv->bas_panel; |
| 503 | break; |
| 504 | case ADVANCED: |
| 505 | builder_ptr = &buttons->priv->advanced_ui; |
| 506 | path = UI_ADVANCED_RESOURCE_PATH"/org/cafe/calculator/ui/buttons-advanced.ui"; |
| 507 | panel = &buttons->priv->adv_panel; |
| 508 | break; |
| 509 | case FINANCIAL: |
| 510 | builder_ptr = &buttons->priv->financial_ui; |
| 511 | path = UI_FINANCIAL_RESOURCE_PATH"/org/cafe/calculator/ui/buttons-financial.ui"; |
| 512 | panel = &buttons->priv->fin_panel; |
| 513 | break; |
| 514 | case PROGRAMMING: |
| 515 | builder_ptr = &buttons->priv->programming_ui; |
| 516 | path = UI_PROGRAMMING_RESOURCE_PATH"/org/cafe/calculator/ui/buttons-programming.ui"; |
| 517 | panel = &buttons->priv->prog_panel; |
| 518 | break; |
| 519 | } |
| 520 | |
| 521 | if (*panel) |
| 522 | goto out; |
| 523 | |
| 524 | builder = *builder_ptr = ctk_builder_new(); |
| 525 | // FIXME: Show dialog if failed to load |
| 526 | ctk_builder_add_objects_from_resource(builder, path, objects, &error); |
| 527 | if (error) { |
| 528 | g_warning("Error loading button UI: %s", error->message); |
| 529 | g_clear_error(&error); |
| 530 | } |
| 531 | *panel = GET_WIDGET(builder, "button_panel")((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object((builder), ("button_panel")))), ( (ctk_widget_get_type ())))))); |
| 532 | ctk_box_pack_end(CTK_BOX(buttons)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons)), ((ctk_box_get_type ())))))), *panel, TRUE(!(0)), TRUE(!(0)), 0); |
| 533 | |
| 534 | /* Configure buttons */ |
| 535 | for (i = 0; button_data[i].widget_name != NULL((void*)0); i++) { |
| 536 | GObject *object; |
| 537 | CtkWidget *button; |
| 538 | |
| 539 | name = g_strdup_printf("calc_%s_button", button_data[i].widget_name); |
| 540 | object = ctk_builder_get_object(*builder_ptr, name); |
| 541 | g_free(name); |
| 542 | |
| 543 | if (!object) |
| 544 | continue; |
| 545 | button = CTK_WIDGET(object)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), ((ctk_widget_get_type ())))))); |
| 546 | if (button_data[i].data) |
| 547 | g_object_set_data(object, "calc_text", (gpointer) button_data[i].data); |
| 548 | |
| 549 | if (button_data[i].tooltip) |
| 550 | ctk_widget_set_tooltip_text(button, _(button_data[i].tooltip)gettext (button_data[i].tooltip)); |
| 551 | |
| 552 | atk_object_set_name(ctk_widget_get_accessible(button), button_data[i].widget_name); |
| 553 | } |
| 554 | |
| 555 | /* Set special button data */ |
| 556 | for (i = 0; i < 16; i++) { |
| 557 | CtkWidget *button; |
| 558 | |
| 559 | name = g_strdup_printf("calc_%d_button", i); |
| 560 | button = GET_WIDGET(builder, name)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object((builder), (name)))), ((ctk_widget_get_type ())))))); |
| 561 | if (button) { |
| 562 | gchar buffer[7]; |
| 563 | gint len; |
| 564 | |
| 565 | g_object_set_data(G_OBJECT(button)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((button)), (((GType) ((20) << (2)))))))), "calc_digit", GINT_TO_POINTER(i)((gpointer) (glong) (i))); |
| 566 | len = g_unichar_to_utf8(math_equation_get_digit_text(buttons->priv->equation, i), buffer); |
| 567 | buffer[len] = '\0'; |
| 568 | ctk_button_set_label(CTK_BUTTON(button)((((CtkButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((button)), ((ctk_button_get_type ())))))), buffer); |
| 569 | } |
| 570 | g_free(name); |
| 571 | } |
| 572 | widget = GET_WIDGET(builder, "calc_numeric_point_button")((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object((builder), ("calc_numeric_point_button" )))), ((ctk_widget_get_type ())))))); |
| 573 | if (widget) { |
| 574 | MpSerializer *serializer = math_equation_get_serializer(buttons->priv->equation); |
| 575 | gchar buffer[7]; |
| 576 | gint len; |
| 577 | len = g_unichar_to_utf8(mp_serializer_get_radix(serializer), buffer); |
| 578 | buffer[len] = '\0'; |
| 579 | ctk_button_set_label(CTK_BUTTON(widget)((((CtkButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_button_get_type ())))))), buffer); |
| 580 | } |
| 581 | |
| 582 | widget = GET_WIDGET(builder, "calc_superscript_button")((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object((builder), ("calc_superscript_button" )))), ((ctk_widget_get_type ())))))); |
| 583 | if (widget) { |
| 584 | buttons->priv->superscript_toggles = g_list_append(buttons->priv->superscript_toggles, widget); |
| 585 | if (math_equation_get_number_mode(buttons->priv->equation) == SUPERSCRIPT) |
| 586 | ctk_toggle_button_set_active(CTK_TOGGLE_BUTTON(widget)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_toggle_button_get_type ())))))), TRUE(!(0))); |
| 587 | } |
| 588 | widget = GET_WIDGET(builder, "calc_subscript_button")((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object((builder), ("calc_subscript_button" )))), ((ctk_widget_get_type ())))))); |
| 589 | if (widget) { |
| 590 | buttons->priv->subscript_toggles = g_list_append(buttons->priv->subscript_toggles, widget); |
| 591 | if (math_equation_get_number_mode(buttons->priv->equation) == SUBSCRIPT) |
| 592 | ctk_toggle_button_set_active(CTK_TOGGLE_BUTTON(widget)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_toggle_button_get_type ())))))), TRUE(!(0))); |
| 593 | } |
| 594 | |
| 595 | /* put the icon name "process-stop" in the buttons |
| 596 | button1, button3, button5, button7, button9, |
| 597 | button11, button13, button15, button17, button19 |
| 598 | taken from buttons-financial.ui */ |
| 599 | for (i = 1; i < 20; i++) { |
| 600 | if (i % 2) { |
| 601 | widget = GET_WIDGET (builder, g_strdup_printf ("button%d",i))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object((builder), (g_strdup_printf ("button%d" ,i))))), ((ctk_widget_get_type ())))))); |
| 602 | if (CTK_IS_BUTTON(widget)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (widget)); GType __t = ((ctk_button_get_type ())); gboolean __r ; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) |
| 603 | ctk_button_set_image (CTK_BUTTON (widget)((((CtkButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_button_get_type ())))))), |
| 604 | ctk_image_new_from_icon_name ("process-stop", CTK_ICON_SIZE_BUTTON)); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | if (mode == PROGRAMMING) { |
| 609 | CtkListStore *model; |
| 610 | CtkTreeIter iter; |
| 611 | CtkCellRenderer *renderer; |
| 612 | |
| 613 | buttons->priv->base_label = GET_WIDGET(builder, "base_label")((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object((builder), ("base_label")))), ((ctk_widget_get_type ())))))); |
| 614 | buttons->priv->character_code_dialog = GET_WIDGET(builder, "character_code_dialog")((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object((builder), ("character_code_dialog" )))), ((ctk_widget_get_type ())))))); |
| 615 | buttons->priv->character_code_entry = GET_WIDGET(builder, "character_code_entry")((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object((builder), ("character_code_entry" )))), ((ctk_widget_get_type ())))))); |
| 616 | |
| 617 | buttons->priv->bit_panel = GET_WIDGET(builder, "bit_table")((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object((builder), ("bit_table")))), ((ctk_widget_get_type ())))))); |
| 618 | for (i = 0; i < MAXBITS64; i++) { |
| 619 | name = g_strdup_printf("bit_label_%d", i); |
| 620 | buttons->priv->bit_labels[i] = GET_WIDGET(builder, name)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object((builder), (name)))), ((ctk_widget_get_type ())))))); |
| 621 | g_free(name); |
| 622 | name = g_strdup_printf("bit_eventbox_%d", i); |
| 623 | set_int_data(builder, name, "bit_index", i); |
| 624 | } |
| 625 | |
| 626 | buttons->priv->base_combo = GET_WIDGET(builder, "base_combo")((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object((builder), ("base_combo")))), ((ctk_widget_get_type ())))))); |
| 627 | model = ctk_list_store_new(2, G_TYPE_STRING((GType) ((16) << (2))), G_TYPE_INT((GType) ((6) << (2))), G_TYPE_INT((GType) ((6) << (2)))); |
| 628 | ctk_combo_box_set_model(CTK_COMBO_BOX(buttons->priv->base_combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons->priv->base_combo)), ((ctk_combo_box_get_type ())))))), CTK_TREE_MODEL(model)((((CtkTreeModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((ctk_tree_model_get_type ()))))))); |
| 629 | ctk_list_store_append(CTK_LIST_STORE(model)((((CtkListStore*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((ctk_list_store_get_type ())))))), &iter); |
| 630 | ctk_list_store_set(CTK_LIST_STORE(model)((((CtkListStore*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((ctk_list_store_get_type ())))))), &iter, 0, |
| 631 | /* Number display mode combo: Binary, e.g. 10011010010₂ */ |
| 632 | _("Binary")gettext ("Binary"), 1, 2, -1); |
| 633 | ctk_list_store_append(CTK_LIST_STORE(model)((((CtkListStore*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((ctk_list_store_get_type ())))))), &iter); |
| 634 | ctk_list_store_set(CTK_LIST_STORE(model)((((CtkListStore*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((ctk_list_store_get_type ())))))), &iter, 0, |
| 635 | /* Number display mode combo: Octal, e.g. 2322₈ */ |
| 636 | _("Octal")gettext ("Octal"), 1, 8, -1); |
| 637 | ctk_list_store_append(CTK_LIST_STORE(model)((((CtkListStore*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((ctk_list_store_get_type ())))))), &iter); |
| 638 | ctk_list_store_set(CTK_LIST_STORE(model)((((CtkListStore*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((ctk_list_store_get_type ())))))), &iter, 0, |
| 639 | /* Number display mode combo: Decimal, e.g. 1234 */ |
| 640 | _("Decimal")gettext ("Decimal"), 1, 10, -1); |
| 641 | ctk_list_store_append(CTK_LIST_STORE(model)((((CtkListStore*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((ctk_list_store_get_type ())))))), &iter); |
| 642 | ctk_list_store_set(CTK_LIST_STORE(model)((((CtkListStore*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((ctk_list_store_get_type ())))))), &iter, 0, |
| 643 | /* Number display mode combo: Hexadecimal, e.g. 4D2₁₆ */ |
| 644 | _("Hexadecimal")gettext ("Hexadecimal"), 1, 16, -1); |
| 645 | renderer = ctk_cell_renderer_text_new(); |
| 646 | ctk_cell_layout_pack_start(CTK_CELL_LAYOUT(buttons->priv->base_combo)((((CtkCellLayout*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons->priv->base_combo)), ((ctk_cell_layout_get_type ())))))), renderer, TRUE(!(0))); |
| 647 | ctk_cell_layout_add_attribute(CTK_CELL_LAYOUT(buttons->priv->base_combo)((((CtkCellLayout*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons->priv->base_combo)), ((ctk_cell_layout_get_type ())))))), renderer, "text", 0); |
| 648 | |
| 649 | g_signal_connect(buttons->priv->base_combo, "changed", G_CALLBACK(base_combobox_changed_cb), buttons)g_signal_connect_data ((buttons->priv->base_combo), ("changed" ), (((GCallback) (base_combobox_changed_cb))), (buttons), ((void *)0), (GConnectFlags) 0); |
| 650 | g_signal_connect(buttons->priv->equation, "notify::base", G_CALLBACK(base_changed_cb), buttons)g_signal_connect_data ((buttons->priv->equation), ("notify::base" ), (((GCallback) (base_changed_cb))), (buttons), ((void*)0), ( GConnectFlags) 0); |
| 651 | base_changed_cb(buttons->priv->equation, NULL((void*)0), buttons); |
| 652 | } |
| 653 | |
| 654 | /* Setup financial functions */ |
| 655 | if (mode == FINANCIAL) { |
| 656 | load_finc_dialogs(buttons); |
| 657 | |
| 658 | set_data(builder, "calc_finc_compounding_term_button", "finc_dialog", "ctrm_dialog"); |
| 659 | set_data(builder, "calc_finc_double_declining_depreciation_button", "finc_dialog", "ddb_dialog"); |
| 660 | set_data(builder, "calc_finc_future_value_button", "finc_dialog", "fv_dialog"); |
| 661 | set_data(builder, "calc_finc_gross_profit_margin_button", "finc_dialog", "gpm_dialog"); |
| 662 | set_data(builder, "calc_finc_periodic_payment_button", "finc_dialog", "pmt_dialog"); |
| 663 | set_data(builder, "calc_finc_present_value_button", "finc_dialog", "pv_dialog"); |
| 664 | set_data(builder, "calc_finc_periodic_interest_rate_button", "finc_dialog", "rate_dialog"); |
| 665 | set_data(builder, "calc_finc_straight_line_depreciation_button", "finc_dialog", "sln_dialog"); |
| 666 | set_data(builder, "calc_finc_sum_of_the_years_digits_depreciation_button", "finc_dialog", "syd_dialog"); |
| 667 | set_data(builder, "calc_finc_term_button", "finc_dialog", "term_dialog"); |
| 668 | } |
| 669 | |
| 670 | ctk_builder_connect_signals(builder, buttons); |
| 671 | |
| 672 | display_changed_cb(buttons->priv->equation, NULL((void*)0), buttons); |
| 673 | |
| 674 | out: |
| 675 | return *panel; |
| 676 | } |
| 677 | |
| 678 | |
| 679 | static void |
| 680 | converter_changed_cb(MathConverter *converter, MathButtons *buttons) |
| 681 | { |
| 682 | Unit *from_unit, *to_unit; |
| 683 | |
| 684 | math_converter_get_conversion(converter, &from_unit, &to_unit); |
| 685 | if (buttons->priv->mode == FINANCIAL) { |
| 686 | math_equation_set_source_currency(buttons->priv->equation, unit_get_name(from_unit)); |
| 687 | math_equation_set_target_currency(buttons->priv->equation, unit_get_name(to_unit)); |
| 688 | } |
| 689 | else { |
| 690 | math_equation_set_source_units(buttons->priv->equation, unit_get_name(from_unit)); |
| 691 | math_equation_set_target_units(buttons->priv->equation, unit_get_name(to_unit)); |
| 692 | } |
| 693 | |
| 694 | g_object_unref(from_unit); |
| 695 | g_object_unref(to_unit); |
| 696 | } |
| 697 | |
| 698 | |
| 699 | static void |
| 700 | load_buttons(MathButtons *buttons) |
| 701 | { |
| 702 | CtkWidget *panel; |
| 703 | |
| 704 | if (!ctk_widget_get_visible(CTK_WIDGET(buttons)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons)), ((ctk_widget_get_type ())))))))) |
| 705 | return; |
| 706 | |
| 707 | if (!buttons->priv->converter) { |
| 708 | buttons->priv->converter = math_converter_new(buttons->priv->equation); |
| 709 | g_signal_connect(buttons->priv->converter, "changed", G_CALLBACK(converter_changed_cb), buttons)g_signal_connect_data ((buttons->priv->converter), ("changed" ), (((GCallback) (converter_changed_cb))), (buttons), ((void* )0), (GConnectFlags) 0); |
| 710 | ctk_box_pack_start(CTK_BOX(buttons)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons)), ((ctk_box_get_type ())))))), CTK_WIDGET(buttons->priv->converter)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons->priv->converter)), ((ctk_widget_get_type ( ))))))), FALSE(0), TRUE(!(0)), 0); |
| 711 | } |
| 712 | |
| 713 | panel = load_mode(buttons, buttons->priv->mode); |
| 714 | if (buttons->priv->active_panel == panel) |
| 715 | return; |
| 716 | |
| 717 | /* Hide old buttons */ |
| 718 | if (buttons->priv->active_panel) |
| 719 | ctk_widget_hide(buttons->priv->active_panel); |
| 720 | |
| 721 | /* Load and display new buttons */ |
| 722 | buttons->priv->active_panel = panel; |
| 723 | if (panel) |
| 724 | ctk_widget_show(panel); |
| 725 | } |
| 726 | |
| 727 | |
| 728 | void |
| 729 | math_buttons_set_mode(MathButtons *buttons, ButtonMode mode) |
| 730 | { |
| 731 | g_return_if_fail(buttons != NULL)do { if ((buttons != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "buttons != NULL" ); return; } } while (0); |
| 732 | |
| 733 | if (buttons->priv->mode == mode) |
| 734 | return; |
| 735 | |
| 736 | buttons->priv->mode = mode; |
| 737 | |
| 738 | if (mode == PROGRAMMING) |
| 739 | math_equation_set_base(buttons->priv->equation, buttons->priv->programming_base); |
| 740 | else |
| 741 | math_equation_set_base(buttons->priv->equation, 10); |
| 742 | |
| 743 | load_buttons(buttons); |
| 744 | |
| 745 | ctk_widget_set_visible(CTK_WIDGET(buttons->priv->converter)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons->priv->converter)), ((ctk_widget_get_type ( ))))))), mode == ADVANCED || mode == FINANCIAL); |
| 746 | if (mode == ADVANCED) { |
| 747 | math_converter_set_category(buttons->priv->converter, NULL((void*)0)); |
| 748 | math_converter_set_conversion(buttons->priv->converter, |
| 749 | math_equation_get_source_units(buttons->priv->equation), |
| 750 | math_equation_get_target_units(buttons->priv->equation)); |
| 751 | } |
| 752 | else if (mode == FINANCIAL) { |
| 753 | math_converter_set_category(buttons->priv->converter, "currency"); |
| 754 | math_converter_set_conversion(buttons->priv->converter, |
| 755 | math_equation_get_source_currency(buttons->priv->equation), |
| 756 | math_equation_get_target_currency(buttons->priv->equation)); |
| 757 | } |
| 758 | |
| 759 | g_object_notify(G_OBJECT(buttons)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons)), (((GType) ((20) << (2)))))))), "mode"); |
| 760 | } |
| 761 | |
| 762 | |
| 763 | ButtonMode |
| 764 | math_buttons_get_mode(MathButtons *buttons) |
| 765 | { |
| 766 | return buttons->priv->mode; |
| 767 | } |
| 768 | |
| 769 | |
| 770 | void |
| 771 | math_buttons_set_programming_base(MathButtons *buttons, gint base) |
| 772 | { |
| 773 | g_return_if_fail(buttons != NULL)do { if ((buttons != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "buttons != NULL" ); return; } } while (0); |
| 774 | |
| 775 | if (base == buttons->priv->programming_base) |
| 776 | return; |
| 777 | |
| 778 | buttons->priv->programming_base = base; |
| 779 | |
| 780 | g_settings_set_int(g_settings_var, "base", math_buttons_get_programming_base(buttons)); |
| 781 | |
| 782 | if (buttons->priv->mode == PROGRAMMING) |
| 783 | math_equation_set_base(buttons->priv->equation, base); |
| 784 | } |
| 785 | |
| 786 | |
| 787 | gint |
| 788 | math_buttons_get_programming_base(MathButtons *buttons) |
| 789 | { |
| 790 | g_return_val_if_fail(buttons != NULL, 10)do { if ((buttons != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "buttons != NULL" ); return (10); } } while (0); |
| 791 | return buttons->priv->programming_base; |
| 792 | } |
| 793 | |
| 794 | |
| 795 | void exponent_cb(CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons); |
| 796 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 797 | void |
| 798 | exponent_cb(CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons) |
| 799 | { |
| 800 | math_equation_insert_exponent(buttons->priv->equation); |
| 801 | } |
| 802 | |
| 803 | |
| 804 | void subtract_cb(CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons); |
| 805 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 806 | void |
| 807 | subtract_cb(CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons) |
| 808 | { |
| 809 | math_equation_insert_subtract(buttons->priv->equation); |
| 810 | } |
| 811 | |
| 812 | |
| 813 | void button_cb(CtkWidget *widget, MathButtons *buttons); |
| 814 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 815 | void |
| 816 | button_cb(CtkWidget *widget, MathButtons *buttons) |
| 817 | { |
| 818 | math_equation_insert(buttons->priv->equation, g_object_get_data(G_OBJECT(widget)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), (((GType) ((20) << (2)))))))), "calc_text")); |
| 819 | } |
| 820 | |
| 821 | |
| 822 | void solve_cb(CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons); |
| 823 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 824 | void |
| 825 | solve_cb(CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons) |
| 826 | { |
| 827 | math_equation_solve(buttons->priv->equation); |
| 828 | } |
| 829 | |
| 830 | |
| 831 | void clear_cb(CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons); |
| 832 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 833 | void |
| 834 | clear_cb(CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons) |
| 835 | { |
| 836 | math_equation_clear(buttons->priv->equation); |
| 837 | } |
| 838 | |
| 839 | |
| 840 | void delete_cb(CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons); |
| 841 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 842 | void |
| 843 | delete_cb(CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons) |
| 844 | { |
| 845 | math_equation_delete(buttons->priv->equation); |
| 846 | } |
| 847 | |
| 848 | |
| 849 | void undo_cb(CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons); |
| 850 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 851 | void |
| 852 | undo_cb(CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons) |
| 853 | { |
| 854 | math_equation_undo(buttons->priv->equation); |
| 855 | } |
| 856 | |
| 857 | |
| 858 | static void |
| 859 | shift_cb(CtkWidget *widget, MathButtons *buttons) |
| 860 | { |
| 861 | math_equation_shift(buttons->priv->equation, GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "shiftcount"))((gint) (glong) (g_object_get_data(((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((widget)), (((GType) ((20) << (2))) ))))), "shiftcount")))); |
| 862 | } |
| 863 | |
| 864 | static void |
| 865 | popup_button_menu(CtkWidget *widget, CtkMenu *menu) |
| 866 | { |
| 867 | ctk_menu_popup_at_widget (menu, |
| 868 | widget, |
| 869 | CDK_GRAVITY_SOUTH_WEST, |
| 870 | CDK_GRAVITY_NORTH_WEST, |
| 871 | NULL((void*)0)); |
| 872 | } |
| 873 | |
| 874 | |
| 875 | void memory_cb(CtkWidget *widget, MathButtons *buttons); |
| 876 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 877 | void |
| 878 | memory_cb(CtkWidget *widget, MathButtons *buttons) |
| 879 | { |
| 880 | MathVariablePopup *popup; |
| 881 | CtkAllocation allocation; |
| 882 | gint x, y; |
| 883 | |
| 884 | popup = math_variable_popup_new(buttons->priv->equation); |
| 885 | ctk_window_set_transient_for(CTK_WINDOW(popup)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((popup)), ((ctk_window_get_type ())))))), CTK_WINDOW(ctk_widget_get_toplevel(widget))((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_widget_get_toplevel(widget))), ((ctk_window_get_type ()))))))); |
| 886 | |
| 887 | ctk_widget_get_allocation(widget, &allocation); |
| 888 | cdk_window_get_root_coords(ctk_widget_get_window(widget), allocation.x, allocation.y, &x, &y); |
| 889 | ctk_window_move(CTK_WINDOW(popup)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((popup)), ((ctk_window_get_type ())))))), x, y); |
| 890 | ctk_widget_show(CTK_WIDGET(popup)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((popup)), ((ctk_widget_get_type ()))))))); |
| 891 | } |
| 892 | |
| 893 | |
| 894 | void shift_left_cb(CtkWidget *widget, MathButtons *buttons); |
| 895 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 896 | void |
| 897 | shift_left_cb(CtkWidget *widget, MathButtons *buttons) |
| 898 | { |
| 899 | if (!buttons->priv->shift_left_menu) { |
| 900 | gint i; |
| 901 | CtkWidget *menu; |
| 902 | |
| 903 | menu = buttons->priv->shift_left_menu = ctk_menu_new(); |
| 904 | ctk_menu_set_reserve_toggle_size(CTK_MENU(menu)((((CtkMenu*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((menu)), ((ctk_menu_get_type ())))))), FALSE(0)); |
| 905 | |
| 906 | for (i = 1; i < 16; i++) { |
| 907 | CtkWidget *item, *label; |
| 908 | gchar *format, *text; |
| 909 | |
| 910 | if (i < 10) { |
| 911 | /* Left Shift Popup: Menu item to shift left by n places (n < 10) */ |
| 912 | format = ngettext("_%d place", "_%d places", i); |
| 913 | } |
| 914 | else { |
| 915 | /* Left Shift Popup: Menu item to shift left by n places (n >= 10) */ |
| 916 | format = ngettext("%d place", "%d places", i); |
| 917 | } |
| 918 | text = g_strdup_printf(format, i); |
| 919 | label = ctk_label_new_with_mnemonic(text); |
| 920 | |
| 921 | item = ctk_menu_item_new(); |
| 922 | g_object_set_data(G_OBJECT(item)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((item)), (((GType) ((20) << (2)))))))), "shiftcount", GINT_TO_POINTER(i)((gpointer) (glong) (i))); |
| 923 | ctk_container_add(CTK_CONTAINER(item)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((item)), ((ctk_container_get_type ())))))), label); |
| 924 | ctk_menu_shell_append(CTK_MENU_SHELL(menu)((((CtkMenuShell*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((menu)), ((ctk_menu_shell_get_type ())))))), item); |
| 925 | g_signal_connect(item, "activate", G_CALLBACK(shift_cb), buttons)g_signal_connect_data ((item), ("activate"), (((GCallback) (shift_cb ))), (buttons), ((void*)0), (GConnectFlags) 0); |
| 926 | |
| 927 | ctk_widget_show(label); |
| 928 | ctk_widget_show(item); |
| 929 | g_free(text); |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | popup_button_menu(widget, CTK_MENU(buttons->priv->shift_left_menu)((((CtkMenu*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons->priv->shift_left_menu)), ((ctk_menu_get_type ()))))))); |
| 934 | } |
| 935 | |
| 936 | |
| 937 | void shift_right_cb(CtkWidget *widget, MathButtons *buttons); |
| 938 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 939 | void |
| 940 | shift_right_cb(CtkWidget *widget, MathButtons *buttons) |
| 941 | { |
| 942 | if (!buttons->priv->shift_right_menu) { |
| 943 | gint i; |
| 944 | CtkWidget *menu; |
| 945 | |
| 946 | menu = buttons->priv->shift_right_menu = ctk_menu_new(); |
| 947 | ctk_menu_set_reserve_toggle_size(CTK_MENU(menu)((((CtkMenu*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((menu)), ((ctk_menu_get_type ())))))), FALSE(0)); |
| 948 | |
| 949 | for (i = 1; i < 16; i++) { |
| 950 | CtkWidget *item, *label; |
| 951 | gchar *format, *text; |
| 952 | |
| 953 | if (i < 10) { |
| 954 | /* Right Shift Popup: Menu item to shift right by n places (n < 10) */ |
| 955 | format = ngettext("_%d place", "_%d places", i); |
| 956 | } |
| 957 | else { |
| 958 | /* Right Shift Popup: Menu item to shift right by n places (n >= 10) */ |
| 959 | format = ngettext("%d place", "%d places", i); |
| 960 | } |
| 961 | text = g_strdup_printf(format, i); |
| 962 | label = ctk_label_new_with_mnemonic(text); |
| 963 | |
| 964 | item = ctk_menu_item_new(); |
| 965 | g_object_set_data(G_OBJECT(item)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((item)), (((GType) ((20) << (2)))))))), "shiftcount", GINT_TO_POINTER(-i)((gpointer) (glong) (-i))); |
| 966 | ctk_container_add(CTK_CONTAINER(item)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((item)), ((ctk_container_get_type ())))))), label); |
| 967 | ctk_menu_shell_append(CTK_MENU_SHELL(menu)((((CtkMenuShell*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((menu)), ((ctk_menu_shell_get_type ())))))), item); |
| 968 | g_signal_connect(item, "activate", G_CALLBACK(shift_cb), buttons)g_signal_connect_data ((item), ("activate"), (((GCallback) (shift_cb ))), (buttons), ((void*)0), (GConnectFlags) 0); |
| 969 | |
| 970 | ctk_widget_show(label); |
| 971 | ctk_widget_show(item); |
| 972 | g_free(text); |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | popup_button_menu(widget, CTK_MENU(buttons->priv->shift_right_menu)((((CtkMenu*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons->priv->shift_right_menu)), ((ctk_menu_get_type ()))))))); |
| 977 | } |
| 978 | |
| 979 | |
| 980 | static void |
| 981 | insert_function_cb(CtkWidget *widget, MathButtons *buttons) |
| 982 | { |
| 983 | math_equation_insert(buttons->priv->equation, g_object_get_data(G_OBJECT(widget)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), (((GType) ((20) << (2)))))))), "function")); |
| 984 | } |
| 985 | |
| 986 | |
| 987 | void function_cb(CtkWidget *widget, MathButtons *buttons); |
| 988 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 989 | void |
| 990 | function_cb(CtkWidget *widget, MathButtons *buttons) |
| 991 | { |
| 992 | if (!buttons->priv->function_menu) { |
| 993 | gint i; |
| 994 | CtkWidget *menu; |
| 995 | struct |
| 996 | { |
| 997 | gchar *name, *function; |
| 998 | } functions[] = |
| 999 | { |
| 1000 | { /* Tooltip for the integer component button */ |
| 1001 | N_("Integer Component")("Integer Component"), "int " }, |
| 1002 | { /* Tooltip for the fractional component button */ |
| 1003 | N_("Fractional Component")("Fractional Component"), "frac " }, |
| 1004 | { /* Tooltip for the round button */ |
| 1005 | N_("Round")("Round"), "round " }, |
| 1006 | { /* Tooltip for the floor button */ |
| 1007 | N_("Floor")("Floor"), "floor " }, |
| 1008 | { /* Tooltip for the ceiling button */ |
| 1009 | N_("Ceiling")("Ceiling"), "ceil " }, |
| 1010 | { /* Tooltip for the ceiling button */ |
| 1011 | N_("Sign")("Sign"), "sgn " }, |
| 1012 | { NULL((void*)0), NULL((void*)0) } |
| 1013 | }; |
| 1014 | |
| 1015 | menu = buttons->priv->function_menu = ctk_menu_new(); |
| 1016 | ctk_menu_set_reserve_toggle_size(CTK_MENU(menu)((((CtkMenu*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((menu)), ((ctk_menu_get_type ())))))), FALSE(0)); |
| 1017 | |
| 1018 | for (i = 0; functions[i].name != NULL((void*)0); i++) { |
| 1019 | CtkWidget *item; |
| 1020 | |
| 1021 | item = ctk_menu_item_new_with_label(_(functions[i].name)gettext (functions[i].name)); |
| 1022 | g_object_set_data(G_OBJECT(item)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((item)), (((GType) ((20) << (2)))))))), "function", g_strdup(functions[i].function)g_strdup_inline (functions[i].function)); |
| 1023 | ctk_menu_shell_append(CTK_MENU_SHELL(menu)((((CtkMenuShell*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((menu)), ((ctk_menu_shell_get_type ())))))), item); |
| 1024 | g_signal_connect(item, "activate", G_CALLBACK(insert_function_cb), buttons)g_signal_connect_data ((item), ("activate"), (((GCallback) (insert_function_cb ))), (buttons), ((void*)0), (GConnectFlags) 0); |
| 1025 | ctk_widget_show(item); |
| 1026 | } |
| 1027 | } |
| 1028 | |
| 1029 | popup_button_menu(widget, CTK_MENU(buttons->priv->function_menu)((((CtkMenu*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons->priv->function_menu)), ((ctk_menu_get_type ()))))))); |
| 1030 | } |
| 1031 | |
| 1032 | static void |
| 1033 | insert_const_cb(CtkWidget *widget, MathButtons *buttons) |
| 1034 | { |
| 1035 | math_equation_insert(buttons->priv->equation, g_object_get_data(G_OBJECT(widget)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), (((GType) ((20) << (2)))))))), "const")); |
| 1036 | } |
| 1037 | |
| 1038 | |
| 1039 | void const_cb(CtkWidget *widget, MathButtons *buttons); |
| 1040 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 1041 | void |
| 1042 | const_cb(CtkWidget *widget, MathButtons *buttons) |
| 1043 | { |
| 1044 | if (!buttons->priv->const_menu) { |
| 1045 | gint i; |
| 1046 | CtkWidget *menu; |
| 1047 | struct |
| 1048 | { |
| 1049 | gchar *name, *constant, *tooltip; |
| 1050 | } constants[] = |
| 1051 | { |
| 1052 | { /* Tooltip for the c₀ component button */ |
| 1053 | N_("Velocity of Light")("Velocity of Light"), "c₀", N_("299,792,458 m/s")("299,792,458 m/s") }, |
| 1054 | { /* Tooltip for the μ₀ component button */ |
| 1055 | N_("Magnetic constant")("Magnetic constant"), "μ₀", N_("1.2566370614×10⁻⁶ N/A²")("1.2566370614×10⁻⁶ N/A²") }, |
| 1056 | { /* Tooltip for the ε₀ button */ |
| 1057 | N_("Electric constant")("Electric constant"), "ε₀", N_("8.85418782×10⁻¹² s⁴A²/m³kg")("8.85418782×10⁻¹² s⁴A²/m³kg") }, |
| 1058 | { /* Tooltip for the G button */ |
| 1059 | N_("Newtonian constant of gravitation")("Newtonian constant of gravitation"), "G", N_("6.67408×10⁻¹¹ m³/(s²kg)")("6.67408×10⁻¹¹ m³/(s²kg)") }, |
| 1060 | { /* Tooltip for the h button */ |
| 1061 | N_("Planck constant")("Planck constant"), "h", N_("6.62607004×10⁻³⁴ m²kg/s")("6.62607004×10⁻³⁴ m²kg/s") }, |
| 1062 | { /* Tooltip for the e button */ |
| 1063 | N_("Elementary charge")("Elementary charge"), "e", N_("1.6021766208(98)×10⁻¹⁹ C")("1.6021766208(98)×10⁻¹⁹ C") }, |
| 1064 | { /* Tooltip for the mₑ button */ |
| 1065 | N_("Electron mass")("Electron mass"), "mₑ", N_("9.10938356×10⁻³¹ kg")("9.10938356×10⁻³¹ kg") }, |
| 1066 | { /* Tooltip for the mₚ button */ |
| 1067 | N_("Proton mass")("Proton mass"), "mₚ", N_("1.672621898(21)×10⁻²⁷ kg")("1.672621898(21)×10⁻²⁷ kg") }, |
| 1068 | { /* Tooltip for the Nₐ button */ |
| 1069 | N_("Avogadro constant")("Avogadro constant"), "Nₐ", N_("6.02214086×10²³ mol⁻¹")("6.02214086×10²³ mol⁻¹") }, |
| 1070 | { NULL((void*)0), NULL((void*)0), NULL((void*)0) } |
| 1071 | }; |
| 1072 | |
| 1073 | menu = buttons->priv->const_menu = ctk_menu_new(); |
| 1074 | ctk_menu_set_reserve_toggle_size(CTK_MENU(menu)((((CtkMenu*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((menu)), ((ctk_menu_get_type ())))))), FALSE(0)); |
| 1075 | |
| 1076 | for (i = 0; constants[i].name != NULL((void*)0); i++) { |
| 1077 | CtkWidget *item; |
| 1078 | |
| 1079 | item = ctk_menu_item_new_with_label(_(constants[i].name)gettext (constants[i].name)); |
| 1080 | ctk_widget_set_tooltip_text(item, _(constants[i].tooltip)gettext (constants[i].tooltip)); |
| 1081 | g_object_set_data(G_OBJECT(item)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((item)), (((GType) ((20) << (2)))))))), "const", g_strdup(constants[i].constant)g_strdup_inline (constants[i].constant)); |
| 1082 | ctk_menu_shell_append(CTK_MENU_SHELL(menu)((((CtkMenuShell*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((menu)), ((ctk_menu_shell_get_type ())))))), item); |
| 1083 | g_signal_connect(item, "activate", G_CALLBACK(insert_const_cb), buttons)g_signal_connect_data ((item), ("activate"), (((GCallback) (insert_const_cb ))), (buttons), ((void*)0), (GConnectFlags) 0); |
| 1084 | ctk_widget_show(item); |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | popup_button_menu(widget, CTK_MENU(buttons->priv->const_menu)((((CtkMenu*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons->priv->const_menu)), ((ctk_menu_get_type ( )))))))); |
| 1089 | } |
| 1090 | |
| 1091 | void factorize_cb(CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons); |
| 1092 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 1093 | void |
| 1094 | factorize_cb(CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons) |
| 1095 | { |
| 1096 | math_equation_factorize(buttons->priv->equation); |
| 1097 | } |
| 1098 | |
| 1099 | |
| 1100 | void digit_cb(CtkWidget *widget, MathButtons *buttons); |
| 1101 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 1102 | void |
| 1103 | digit_cb(CtkWidget *widget, MathButtons *buttons) |
| 1104 | { |
| 1105 | math_equation_insert_digit(buttons->priv->equation, GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "calc_digit"))((gint) (glong) (g_object_get_data(((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((widget)), (((GType) ((20) << (2))) ))))), "calc_digit")))); |
| 1106 | } |
| 1107 | |
| 1108 | |
| 1109 | void numeric_point_cb(CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons); |
| 1110 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 1111 | void |
| 1112 | numeric_point_cb(CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons) |
| 1113 | { |
| 1114 | math_equation_insert_numeric_point(buttons->priv->equation); |
| 1115 | } |
| 1116 | |
| 1117 | |
| 1118 | |
| 1119 | void finc_cb(CtkWidget *widget, MathButtons *buttons); |
| 1120 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 1121 | void |
| 1122 | finc_cb(CtkWidget *widget, MathButtons *buttons) |
| 1123 | { |
| 1124 | gchar *name; |
| 1125 | |
| 1126 | name = g_object_get_data(G_OBJECT(widget)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), (((GType) ((20) << (2)))))))), "finc_dialog"); |
| 1127 | ctk_dialog_run(CTK_DIALOG(GET_WIDGET(buttons->priv->financial_ui, name))((((CtkDialog*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object((buttons->priv->financial_ui ), (name)))), ((ctk_widget_get_type ())))))))), ((ctk_dialog_get_type ()))))))); |
| 1128 | ctk_widget_hide(CTK_WIDGET(GET_WIDGET(buttons->priv->financial_ui, name))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object((buttons->priv->financial_ui ), (name)))), ((ctk_widget_get_type ())))))))), ((ctk_widget_get_type ()))))))); |
| 1129 | } |
| 1130 | |
| 1131 | |
| 1132 | void insert_character_code_cb(CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons); |
| 1133 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 1134 | void |
| 1135 | insert_character_code_cb(CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons) |
| 1136 | { |
| 1137 | ctk_window_present(CTK_WINDOW(buttons->priv->character_code_dialog)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons->priv->character_code_dialog)), ((ctk_window_get_type ()))))))); |
| 1138 | } |
| 1139 | |
| 1140 | |
| 1141 | void finc_activate_cb(CtkWidget *widget, MathButtons *buttons); |
| 1142 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 1143 | void |
| 1144 | finc_activate_cb(CtkWidget *widget, MathButtons *buttons) |
| 1145 | { |
| 1146 | gint dialog, field; |
| 1147 | |
| 1148 | dialog = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "finc_dialog"))((gint) (glong) (g_object_get_data(((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((widget)), (((GType) ((20) << (2))) ))))), "finc_dialog"))); |
| 1149 | field = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "finc_field"))((gint) (glong) (g_object_get_data(((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((widget)), (((GType) ((20) << (2))) ))))), "finc_field"))); |
| 1150 | |
| 1151 | if (finc_dialog_fields[dialog][field+1] == NULL((void*)0)) { |
| 1152 | CtkWidget *dialog_widget; |
| 1153 | dialog_widget = ctk_widget_get_toplevel(widget); |
| 1154 | if (ctk_widget_is_toplevel(dialog_widget)) { |
| 1155 | ctk_dialog_response(CTK_DIALOG(dialog_widget)((((CtkDialog*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog_widget)), ((ctk_dialog_get_type ())))))), |
| 1156 | CTK_RESPONSE_OK); |
| 1157 | return; |
| 1158 | } |
| 1159 | } |
| 1160 | else { |
| 1161 | CtkWidget *next_widget; |
| 1162 | next_widget = GET_WIDGET(buttons->priv->financial_ui, finc_dialog_fields[dialog][field+1])((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object((buttons->priv->financial_ui ), (finc_dialog_fields[dialog][field+1])))), ((ctk_widget_get_type ())))))); |
| 1163 | ctk_widget_grab_focus(next_widget); |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | |
| 1168 | void finc_response_cb(CtkWidget *widget, gint response_id, MathButtons *buttons); |
| 1169 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 1170 | void |
| 1171 | finc_response_cb(CtkWidget *widget, gint response_id, MathButtons *buttons) |
| 1172 | { |
| 1173 | int dialog; |
| 1174 | int i; |
| 1175 | MPNumber arg[4]; |
| 1176 | CtkWidget *entry; |
| 1177 | |
| 1178 | if (response_id != CTK_RESPONSE_OK) |
| 1179 | return; |
| 1180 | |
| 1181 | dialog = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "finc_dialog"))((gint) (glong) (g_object_get_data(((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((widget)), (((GType) ((20) << (2))) ))))), "finc_dialog"))); |
| 1182 | |
| 1183 | for (i = 0; i < 4; i++) { |
| 1184 | if (finc_dialog_fields[dialog][i] == NULL((void*)0)) { |
| 1185 | continue; |
| 1186 | } |
| 1187 | entry = GET_WIDGET(buttons->priv->financial_ui, finc_dialog_fields[dialog][i])((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object((buttons->priv->financial_ui ), (finc_dialog_fields[dialog][i])))), ((ctk_widget_get_type ( ))))))); |
| 1188 | mp_set_from_string(ctk_entry_get_text(CTK_ENTRY(entry)((((CtkEntry*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((entry)), ((ctk_entry_get_type ()))))))), 10, &arg[i]); |
| 1189 | ctk_entry_set_text(CTK_ENTRY(entry)((((CtkEntry*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((entry)), ((ctk_entry_get_type ())))))), "0"); |
| 1190 | } |
| 1191 | ctk_widget_grab_focus(GET_WIDGET(buttons->priv->financial_ui, finc_dialog_fields[dialog][0])((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object((buttons->priv->financial_ui ), (finc_dialog_fields[dialog][0])))), ((ctk_widget_get_type ( )))))))); |
| 1192 | |
| 1193 | do_finc_expression(buttons->priv->equation, dialog, &arg[0], &arg[1], &arg[2], &arg[3]); |
| 1194 | } |
| 1195 | |
| 1196 | |
| 1197 | void character_code_dialog_response_cb(CtkWidget *dialog, gint response_id, MathButtons *buttons); |
| 1198 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 1199 | void |
| 1200 | character_code_dialog_response_cb(CtkWidget *dialog, gint response_id, MathButtons *buttons) |
| 1201 | { |
| 1202 | const gchar *text; |
| 1203 | |
| 1204 | text = ctk_entry_get_text(CTK_ENTRY(buttons->priv->character_code_entry)((((CtkEntry*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons->priv->character_code_entry)), ((ctk_entry_get_type ()))))))); |
| 1205 | |
| 1206 | if (response_id == CTK_RESPONSE_OK) { |
| 1207 | MPNumber x; |
| 1208 | int i = 0; |
| 1209 | |
| 1210 | mp_set_from_integer(0, &x); |
| 1211 | while (TRUE(!(0))) { |
| 1212 | mp_add_integer(&x, text[i], &x); |
| 1213 | if (text[i+1]) { |
| 1214 | mp_shift(&x, 8, &x); |
| 1215 | i++; |
| 1216 | } |
| 1217 | else |
| 1218 | break; |
| 1219 | } |
| 1220 | |
| 1221 | math_equation_insert_number(buttons->priv->equation, &x); |
| 1222 | } |
| 1223 | |
| 1224 | ctk_widget_hide(dialog); |
| 1225 | } |
| 1226 | |
| 1227 | |
| 1228 | void character_code_dialog_activate_cb(CtkWidget *entry G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons); |
| 1229 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 1230 | void |
| 1231 | character_code_dialog_activate_cb(CtkWidget *entry G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons) |
| 1232 | { |
| 1233 | character_code_dialog_response_cb(buttons->priv->character_code_dialog, CTK_RESPONSE_OK, buttons); |
| 1234 | } |
| 1235 | |
| 1236 | |
| 1237 | gboolean character_code_dialog_delete_cb(CtkWidget *dialog, CdkEvent *event G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons); |
| 1238 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 1239 | gboolean |
| 1240 | character_code_dialog_delete_cb(CtkWidget *dialog, CdkEvent *event G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons) |
| 1241 | { |
| 1242 | character_code_dialog_response_cb(dialog, CTK_RESPONSE_CANCEL, buttons); |
| 1243 | return TRUE(!(0)); |
| 1244 | } |
| 1245 | |
| 1246 | |
| 1247 | gboolean bit_toggle_cb(CtkWidget *event_box, CdkEventButton *event G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons); |
| 1248 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 1249 | gboolean |
| 1250 | bit_toggle_cb(CtkWidget *event_box, CdkEventButton *event G_GNUC_UNUSED__attribute__ ((__unused__)), MathButtons *buttons) |
| 1251 | { |
| 1252 | math_equation_toggle_bit(buttons->priv->equation, GPOINTER_TO_INT(g_object_get_data(G_OBJECT(event_box), "bit_index"))((gint) (glong) (g_object_get_data(((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((event_box)), (((GType) ((20) << (2 )))))))), "bit_index")))); |
| 1253 | return TRUE(!(0)); |
| 1254 | } |
| 1255 | |
| 1256 | |
| 1257 | static void |
| 1258 | remove_trailing_spaces(MathButtons *buttons) |
| 1259 | { |
| 1260 | CtkTextMark *insert_mark; |
| 1261 | CtkTextIter start, end; |
| 1262 | insert_mark = ctk_text_buffer_get_insert (CTK_TEXT_BUFFER(buttons->priv->equation)((((CtkTextBuffer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons->priv->equation)), ((ctk_text_buffer_get_type ()))))))); |
| 1263 | ctk_text_buffer_get_iter_at_mark(CTK_TEXT_BUFFER(buttons->priv->equation)((((CtkTextBuffer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons->priv->equation)), ((ctk_text_buffer_get_type ())))))), &end, insert_mark); |
| 1264 | start = end; |
| 1265 | while (ctk_text_iter_backward_char(&start)) { |
| 1266 | if (!g_unichar_isspace(ctk_text_iter_get_char(&start))) |
| 1267 | break; |
| 1268 | ctk_text_buffer_delete(CTK_TEXT_BUFFER(buttons->priv->equation)((((CtkTextBuffer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons->priv->equation)), ((ctk_text_buffer_get_type ())))))), &start, &end); |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | |
| 1273 | void set_superscript_cb(CtkWidget *widget, MathButtons *buttons); |
| 1274 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 1275 | void |
| 1276 | set_superscript_cb(CtkWidget *widget, MathButtons *buttons) |
| 1277 | { |
| 1278 | if (ctk_toggle_button_get_active(CTK_TOGGLE_BUTTON(widget)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_toggle_button_get_type ())))))))) { |
| 1279 | math_equation_set_number_mode(buttons->priv->equation, SUPERSCRIPT); |
| 1280 | if (!ctk_text_buffer_get_has_selection(CTK_TEXT_BUFFER(buttons->priv->equation)((((CtkTextBuffer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons->priv->equation)), ((ctk_text_buffer_get_type ())))))))) { |
| 1281 | remove_trailing_spaces(buttons); |
| 1282 | } |
| 1283 | } |
| 1284 | else if (math_equation_get_number_mode(buttons->priv->equation) == SUPERSCRIPT) |
| 1285 | math_equation_set_number_mode(buttons->priv->equation, NORMAL); |
| 1286 | } |
| 1287 | |
| 1288 | |
| 1289 | void set_subscript_cb(CtkWidget *widget, MathButtons *buttons); |
| 1290 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
| 1291 | void |
| 1292 | set_subscript_cb(CtkWidget *widget, MathButtons *buttons) |
| 1293 | { |
| 1294 | if (ctk_toggle_button_get_active(CTK_TOGGLE_BUTTON(widget)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_toggle_button_get_type ())))))))) { |
| 1295 | math_equation_set_number_mode(buttons->priv->equation, SUBSCRIPT); |
| 1296 | if (!ctk_text_buffer_get_has_selection(CTK_TEXT_BUFFER(buttons->priv->equation)((((CtkTextBuffer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons->priv->equation)), ((ctk_text_buffer_get_type ())))))))) { |
| 1297 | remove_trailing_spaces(buttons); |
| 1298 | } |
| 1299 | } |
| 1300 | else if (math_equation_get_number_mode(buttons->priv->equation) == SUBSCRIPT) |
| 1301 | math_equation_set_number_mode(buttons->priv->equation, NORMAL); |
| 1302 | } |
| 1303 | |
| 1304 | |
| 1305 | static void |
| 1306 | number_mode_changed_cb (MathEquation *equation, |
| 1307 | GParamSpec *spec G_GNUC_UNUSED__attribute__ ((__unused__)), |
| 1308 | MathButtons *buttons) |
| 1309 | { |
| 1310 | GList *i; |
| 1311 | NumberMode mode; |
| 1312 | |
| 1313 | mode = math_equation_get_number_mode(equation); |
| 1314 | |
| 1315 | for (i = buttons->priv->superscript_toggles; i; i = i->next) { |
| 1316 | CtkWidget *widget = i->data; |
| 1317 | ctk_toggle_button_set_active(CTK_TOGGLE_BUTTON(widget)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_toggle_button_get_type ())))))), mode == SUPERSCRIPT); |
| 1318 | } |
| 1319 | for (i = buttons->priv->subscript_toggles; i; i = i->next) { |
| 1320 | CtkWidget *widget = i->data; |
| 1321 | ctk_toggle_button_set_active(CTK_TOGGLE_BUTTON(widget)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_toggle_button_get_type ())))))), mode == SUBSCRIPT); |
| 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | |
| 1326 | static void |
| 1327 | math_buttons_set_property(GObject *object, |
| 1328 | guint prop_id, |
| 1329 | const GValue *value, |
| 1330 | GParamSpec *pspec) |
| 1331 | { |
| 1332 | MathButtons *self; |
| 1333 | |
| 1334 | self = MATH_BUTTONS(object)((((MathButtons*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), (math_buttons_get_type()))))); |
| 1335 | |
| 1336 | switch (prop_id) { |
| 1337 | case PROP_EQUATION: |
| 1338 | self->priv->equation = g_value_get_object(value); |
| 1339 | math_buttons_set_mode(self, self->priv->mode); |
| 1340 | g_signal_connect(self->priv->equation, "notify::display", G_CALLBACK(display_changed_cb), self)g_signal_connect_data ((self->priv->equation), ("notify::display" ), (((GCallback) (display_changed_cb))), (self), ((void*)0), ( GConnectFlags) 0); |
| 1341 | g_signal_connect(self->priv->equation, "notify::number-mode", G_CALLBACK(number_mode_changed_cb), self)g_signal_connect_data ((self->priv->equation), ("notify::number-mode" ), (((GCallback) (number_mode_changed_cb))), (self), ((void*) 0), (GConnectFlags) 0); |
| 1342 | g_signal_connect(self->priv->equation, "notify::angle-units", G_CALLBACK(display_changed_cb), self)g_signal_connect_data ((self->priv->equation), ("notify::angle-units" ), (((GCallback) (display_changed_cb))), (self), ((void*)0), ( GConnectFlags) 0); |
| 1343 | g_signal_connect(self->priv->equation, "notify::number-format", G_CALLBACK(display_changed_cb), self)g_signal_connect_data ((self->priv->equation), ("notify::number-format" ), (((GCallback) (display_changed_cb))), (self), ((void*)0), ( GConnectFlags) 0); |
| 1344 | number_mode_changed_cb(self->priv->equation, NULL((void*)0), self); |
| 1345 | display_changed_cb(self->priv->equation, NULL((void*)0), self); |
| 1346 | break; |
| 1347 | case PROP_MODE: |
| 1348 | math_buttons_set_mode(self, g_value_get_int(value)); |
| 1349 | break; |
| 1350 | case PROP_PROGRAMMING_BASE: |
| 1351 | math_buttons_set_programming_base(self, g_value_get_int(value)); |
| 1352 | break; |
| 1353 | default: |
| 1354 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec)do { GObject *_glib__object = (GObject*) ((object)); GParamSpec *_glib__pspec = (GParamSpec*) ((pspec)); guint _glib__property_id = ((prop_id)); g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'" , "math-buttons.c", 1354, ("property"), _glib__property_id, _glib__pspec ->name, g_type_name ((((((GTypeClass*) (((GTypeInstance*) ( _glib__pspec))->g_class))->g_type)))), (g_type_name ((( (((GTypeClass*) (((GTypeInstance*) (_glib__object))->g_class ))->g_type)))))); } while (0); |
| 1355 | break; |
| 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | |
| 1360 | static void |
| 1361 | math_buttons_get_property(GObject *object, |
| 1362 | guint prop_id, |
| 1363 | GValue *value, |
| 1364 | GParamSpec *pspec) |
| 1365 | { |
| 1366 | MathButtons *self; |
| 1367 | |
| 1368 | self = MATH_BUTTONS(object)((((MathButtons*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), (math_buttons_get_type()))))); |
| 1369 | |
| 1370 | switch (prop_id) { |
| 1371 | case PROP_EQUATION: |
| 1372 | g_value_set_object(value, self->priv->equation); |
| 1373 | break; |
| 1374 | case PROP_MODE: |
| 1375 | g_value_set_int(value, self->priv->mode); |
| 1376 | break; |
| 1377 | case PROP_PROGRAMMING_BASE: |
| 1378 | g_value_set_int(value, math_buttons_get_programming_base(self)); |
| 1379 | break; |
| 1380 | default: |
| 1381 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec)do { GObject *_glib__object = (GObject*) ((object)); GParamSpec *_glib__pspec = (GParamSpec*) ((pspec)); guint _glib__property_id = ((prop_id)); g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'" , "math-buttons.c", 1381, ("property"), _glib__property_id, _glib__pspec ->name, g_type_name ((((((GTypeClass*) (((GTypeInstance*) ( _glib__pspec))->g_class))->g_type)))), (g_type_name ((( (((GTypeClass*) (((GTypeInstance*) (_glib__object))->g_class ))->g_type)))))); } while (0); |
| 1382 | break; |
| 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | |
| 1387 | static void |
| 1388 | math_buttons_class_init(MathButtonsClass *klass) |
| 1389 | { |
| 1390 | static GEnumValue button_mode_values[] = |
| 1391 | { |
| 1392 | {BASIC, "basic", "basic"}, |
| 1393 | {ADVANCED, "advanced", "advanced"}, |
| 1394 | {FINANCIAL, "financial", "financial"}, |
| 1395 | {PROGRAMMING, "programming", "programming"}, |
| 1396 | {0, NULL((void*)0), NULL((void*)0)} |
| 1397 | }; |
| 1398 | GObjectClass *object_class = G_OBJECT_CLASS(klass)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((klass)), (((GType) ((20) << (2)))))))); |
| 1399 | |
| 1400 | object_class->get_property = math_buttons_get_property; |
| 1401 | object_class->set_property = math_buttons_set_property; |
| 1402 | |
| 1403 | button_mode_type = g_enum_register_static("ButtonMode", button_mode_values); |
| 1404 | |
| 1405 | g_object_class_install_property(object_class, |
| 1406 | PROP_EQUATION, |
| 1407 | g_param_spec_object("equation", |
| 1408 | "equation", |
| 1409 | "Equation being controlled", |
| 1410 | math_equation_get_type(), |
| 1411 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); |
| 1412 | g_object_class_install_property(object_class, |
| 1413 | PROP_MODE, |
| 1414 | g_param_spec_enum("mode", |
| 1415 | "mode", |
| 1416 | "Button mode", |
| 1417 | button_mode_type, |
| 1418 | BASIC, |
| 1419 | G_PARAM_READWRITE)); |
| 1420 | g_object_class_install_property(object_class, |
| 1421 | PROP_PROGRAMMING_BASE, |
| 1422 | g_param_spec_int("programming-base", |
| 1423 | "programming-base", |
| 1424 | "Base to use in programming mode", |
| 1425 | 2, 16, 10, |
| 1426 | G_PARAM_READWRITE)); |
| 1427 | } |
| 1428 | |
| 1429 | |
| 1430 | static void |
| 1431 | math_buttons_init(MathButtons *buttons) |
| 1432 | { |
| 1433 | buttons->priv = math_buttons_get_instance_private (buttons); |
| 1434 | ctk_box_set_spacing(CTK_BOX(buttons)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons)), ((ctk_box_get_type ())))))), 6); |
| 1435 | ctk_orientable_set_orientation (CTK_ORIENTABLE (buttons)((((CtkOrientable*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons)), ((ctk_orientable_get_type ())))))), |
| 1436 | CTK_ORIENTATION_VERTICAL); |
| 1437 | buttons->priv->programming_base = 10; |
| 1438 | g_signal_connect(G_OBJECT(buttons), "show", G_CALLBACK(load_buttons), NULL)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((buttons)), (((GType) ((20) << (2)) ))))))), ("show"), (((GCallback) (load_buttons))), (((void*)0 )), ((void*)0), (GConnectFlags) 0); |
| 1439 | } |