Bug Summary

File:math-buttons.c
Warning:line 477, column 9
Value stored to 'valid' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name math-buttons.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/rootdir/src -fcoverage-compilation-dir=/rootdir/src -resource-dir /usr/lib/llvm-19/lib/clang/19 -D HAVE_CONFIG_H -I . -I .. -D VERSION="1.25.0" -D LOCALE_DIR="/usr/share/locale" -D GETTEXT_PACKAGE="cafe-calc" -I /usr/include/ctk-3.0 -I /usr/include/pango-1.0 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -I /usr/include/gio-unix-2.0 -I /usr/include/atk-1.0 -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -I /usr/include/libxml2 -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2025-08-17-015615-15323-1 -x c math-buttons.c
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
20enum {
21 PROP_0,
22 PROP_EQUATION,
23 PROP_MODE,
24 PROP_PROGRAMMING_BASE
25};
26
27static GType button_mode_type;
28
29#define MAXBITS64 64 /* Bit panel: number of bit fields. */
30
31struct 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
62G_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
75typedef enum
76{
77 NUMBER,
78 NUMBER_BOLD,
79 OPERATOR,
80 FUNCTION,
81 MEMORY,
82 GROUP,
83 ACTION
84} ButtonClass;
85
86typedef struct {
87 const char *widget_name;
88 const char *data;
89 ButtonClass class;
90 const char *tooltip;
91} ButtonData;
92
93static 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 */
292static 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
307MathButtons *
308math_buttons_new(MathEquation *equation)
309{
310 return g_object_new(math_buttons_get_type(), "equation", equation, NULL((void*)0));
311}
312
313static void
314set_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
323static void
324set_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
333static void
334load_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
360static void
361update_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
428static void
429display_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
437static void
438base_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
452static void
453base_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
483static CtkWidget *
484load_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
674out:
675 return *panel;
676}
677
678
679static void
680converter_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
699static void
700load_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
728void
729math_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
763ButtonMode
764math_buttons_get_mode(MathButtons *buttons)
765{
766 return buttons->priv->mode;
767}
768
769
770void
771math_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
787gint
788math_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
795void exponent_cb (CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)),
796 MathButtons *buttons)
797{
798 math_equation_insert_exponent(buttons->priv->equation);
799}
800
801
802void subtract_cb (CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)),
803 MathButtons *buttons)
804{
805 math_equation_insert_subtract(buttons->priv->equation);
806}
807
808
809void button_cb (CtkWidget *widget,
810 MathButtons *buttons)
811{
812 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"));
813}
814
815
816void solve_cb (CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)),
817 MathButtons *buttons)
818{
819 math_equation_solve(buttons->priv->equation);
820}
821
822
823void clear_cb (CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)),
824 MathButtons *buttons)
825{
826 math_equation_clear(buttons->priv->equation);
827}
828
829
830void delete_cb (CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)),
831 MathButtons *buttons)
832{
833 math_equation_delete(buttons->priv->equation);
834}
835
836
837void undo_cb (CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)),
838 MathButtons *buttons)
839{
840 math_equation_undo(buttons->priv->equation);
841}
842
843
844static void
845shift_cb(CtkWidget *widget, MathButtons *buttons)
846{
847 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")))
);
848}
849
850static void
851popup_button_menu(CtkWidget *widget, CtkMenu *menu)
852{
853 ctk_menu_popup_at_widget (menu,
854 widget,
855 CDK_GRAVITY_SOUTH_WEST,
856 CDK_GRAVITY_NORTH_WEST,
857 NULL((void*)0));
858}
859
860
861void memory_cb (CtkWidget *widget,
862 MathButtons *buttons)
863{
864 MathVariablePopup *popup;
865 CtkAllocation allocation;
866 gint x, y;
867
868 popup = math_variable_popup_new(buttons->priv->equation);
869 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
()))))))
);
870
871 ctk_widget_get_allocation(widget, &allocation);
872 cdk_window_get_root_coords(ctk_widget_get_window(widget), allocation.x, allocation.y, &x, &y);
873 ctk_window_move(CTK_WINDOW(popup)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((popup)), ((ctk_window_get_type ()))))))
, x, y);
874 ctk_widget_show(CTK_WIDGET(popup)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((popup)), ((ctk_widget_get_type ()))))))
);
875}
876
877
878void shift_left_cb (CtkWidget *widget,
879 MathButtons *buttons)
880{
881 if (!buttons->priv->shift_left_menu) {
882 gint i;
883 CtkWidget *menu;
884
885 menu = buttons->priv->shift_left_menu = ctk_menu_new();
886 ctk_menu_set_reserve_toggle_size(CTK_MENU(menu)((((CtkMenu*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((menu)), ((ctk_menu_get_type ()))))))
, FALSE(0));
887
888 for (i = 1; i < 16; i++) {
889 CtkWidget *item, *label;
890 gchar *format, *text;
891
892 if (i < 10) {
893 /* Left Shift Popup: Menu item to shift left by n places (n < 10) */
894 format = ngettext("_%d place", "_%d places", i);
895 }
896 else {
897 /* Left Shift Popup: Menu item to shift left by n places (n >= 10) */
898 format = ngettext("%d place", "%d places", i);
899 }
900 text = g_strdup_printf(format, i);
901 label = ctk_label_new_with_mnemonic(text);
902
903 item = ctk_menu_item_new();
904 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)));
905 ctk_container_add(CTK_CONTAINER(item)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((item)), ((ctk_container_get_type ()))))))
, label);
906 ctk_menu_shell_append(CTK_MENU_SHELL(menu)((((CtkMenuShell*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((menu)), ((ctk_menu_shell_get_type ()))))))
, item);
907 g_signal_connect(item, "activate", G_CALLBACK(shift_cb), buttons)g_signal_connect_data ((item), ("activate"), (((GCallback) (shift_cb
))), (buttons), ((void*)0), (GConnectFlags) 0)
;
908
909 ctk_widget_show(label);
910 ctk_widget_show(item);
911 g_free(text);
912 }
913 }
914
915 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
()))))))
);
916}
917
918
919void shift_right_cb (CtkWidget *widget,
920 MathButtons *buttons)
921{
922 if (!buttons->priv->shift_right_menu) {
923 gint i;
924 CtkWidget *menu;
925
926 menu = buttons->priv->shift_right_menu = ctk_menu_new();
927 ctk_menu_set_reserve_toggle_size(CTK_MENU(menu)((((CtkMenu*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((menu)), ((ctk_menu_get_type ()))))))
, FALSE(0));
928
929 for (i = 1; i < 16; i++) {
930 CtkWidget *item, *label;
931 gchar *format, *text;
932
933 if (i < 10) {
934 /* Right Shift Popup: Menu item to shift right by n places (n < 10) */
935 format = ngettext("_%d place", "_%d places", i);
936 }
937 else {
938 /* Right Shift Popup: Menu item to shift right by n places (n >= 10) */
939 format = ngettext("%d place", "%d places", i);
940 }
941 text = g_strdup_printf(format, i);
942 label = ctk_label_new_with_mnemonic(text);
943
944 item = ctk_menu_item_new();
945 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)));
946 ctk_container_add(CTK_CONTAINER(item)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((item)), ((ctk_container_get_type ()))))))
, label);
947 ctk_menu_shell_append(CTK_MENU_SHELL(menu)((((CtkMenuShell*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((menu)), ((ctk_menu_shell_get_type ()))))))
, item);
948 g_signal_connect(item, "activate", G_CALLBACK(shift_cb), buttons)g_signal_connect_data ((item), ("activate"), (((GCallback) (shift_cb
))), (buttons), ((void*)0), (GConnectFlags) 0)
;
949
950 ctk_widget_show(label);
951 ctk_widget_show(item);
952 g_free(text);
953 }
954 }
955
956 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
()))))))
);
957}
958
959
960static void
961insert_function_cb(CtkWidget *widget, MathButtons *buttons)
962{
963 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"));
964}
965
966
967void function_cb (CtkWidget *widget,
968 MathButtons *buttons)
969{
970 if (!buttons->priv->function_menu) {
971 gint i;
972 CtkWidget *menu;
973 struct
974 {
975 gchar *name, *function;
976 } functions[] =
977 {
978 { /* Tooltip for the integer component button */
979 N_("Integer Component")("Integer Component"), "int " },
980 { /* Tooltip for the fractional component button */
981 N_("Fractional Component")("Fractional Component"), "frac " },
982 { /* Tooltip for the round button */
983 N_("Round")("Round"), "round " },
984 { /* Tooltip for the floor button */
985 N_("Floor")("Floor"), "floor " },
986 { /* Tooltip for the ceiling button */
987 N_("Ceiling")("Ceiling"), "ceil " },
988 { /* Tooltip for the ceiling button */
989 N_("Sign")("Sign"), "sgn " },
990 { NULL((void*)0), NULL((void*)0) }
991 };
992
993 menu = buttons->priv->function_menu = ctk_menu_new();
994 ctk_menu_set_reserve_toggle_size(CTK_MENU(menu)((((CtkMenu*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((menu)), ((ctk_menu_get_type ()))))))
, FALSE(0));
995
996 for (i = 0; functions[i].name != NULL((void*)0); i++) {
997 CtkWidget *item;
998
999 item = ctk_menu_item_new_with_label(_(functions[i].name)gettext (functions[i].name));
1000 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));
1001 ctk_menu_shell_append(CTK_MENU_SHELL(menu)((((CtkMenuShell*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((menu)), ((ctk_menu_shell_get_type ()))))))
, item);
1002 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)
;
1003 ctk_widget_show(item);
1004 }
1005 }
1006
1007 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
()))))))
);
1008}
1009
1010static void
1011insert_const_cb(CtkWidget *widget, MathButtons *buttons)
1012{
1013 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"));
1014}
1015
1016
1017void const_cb (CtkWidget *widget,
1018 MathButtons *buttons)
1019{
1020 if (!buttons->priv->const_menu) {
1021 gint i;
1022 CtkWidget *menu;
1023 struct
1024 {
1025 gchar *name, *constant, *tooltip;
1026 } constants[] =
1027 {
1028 { /* Tooltip for the c₀ component button */
1029 N_("Velocity of Light")("Velocity of Light"), "c₀", N_("299,792,458 m/s")("299,792,458 m/s") },
1030 { /* Tooltip for the μ₀ component button */
1031 N_("Magnetic constant")("Magnetic constant"), "μ₀", N_("1.2566370614×10⁻⁶ N/A²")("1.2566370614×10⁻⁶ N/A²") },
1032 { /* Tooltip for the ε₀ button */
1033 N_("Electric constant")("Electric constant"), "ε₀", N_("8.85418782×10⁻¹² s⁴A²/m³kg")("8.85418782×10⁻¹² s⁴A²/m³kg") },
1034 { /* Tooltip for the G button */
1035 N_("Newtonian constant of gravitation")("Newtonian constant of gravitation"), "G", N_("6.67408×10⁻¹¹ m³/(s²kg)")("6.67408×10⁻¹¹ m³/(s²kg)") },
1036 { /* Tooltip for the h button */
1037 N_("Planck constant")("Planck constant"), "h", N_("6.62607004×10⁻³⁴ m²kg/s")("6.62607004×10⁻³⁴ m²kg/s") },
1038 { /* Tooltip for the e button */
1039 N_("Elementary charge")("Elementary charge"), "e", N_("1.6021766208(98)×10⁻¹⁹ C")("1.6021766208(98)×10⁻¹⁹ C") },
1040 { /* Tooltip for the mₑ button */
1041 N_("Electron mass")("Electron mass"), "mₑ", N_("9.10938356×10⁻³¹ kg")("9.10938356×10⁻³¹ kg") },
1042 { /* Tooltip for the mₚ button */
1043 N_("Proton mass")("Proton mass"), "mₚ", N_("1.672621898(21)×10⁻²⁷ kg")("1.672621898(21)×10⁻²⁷ kg") },
1044 { /* Tooltip for the Nₐ button */
1045 N_("Avogadro constant")("Avogadro constant"), "Nₐ", N_("6.02214086×10²³ mol⁻¹")("6.02214086×10²³ mol⁻¹") },
1046 { NULL((void*)0), NULL((void*)0), NULL((void*)0) }
1047 };
1048
1049 menu = buttons->priv->const_menu = ctk_menu_new();
1050 ctk_menu_set_reserve_toggle_size(CTK_MENU(menu)((((CtkMenu*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((menu)), ((ctk_menu_get_type ()))))))
, FALSE(0));
1051
1052 for (i = 0; constants[i].name != NULL((void*)0); i++) {
1053 CtkWidget *item;
1054
1055 item = ctk_menu_item_new_with_label(_(constants[i].name)gettext (constants[i].name));
1056 ctk_widget_set_tooltip_text(item, _(constants[i].tooltip)gettext (constants[i].tooltip));
1057 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));
1058 ctk_menu_shell_append(CTK_MENU_SHELL(menu)((((CtkMenuShell*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((menu)), ((ctk_menu_shell_get_type ()))))))
, item);
1059 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)
;
1060 ctk_widget_show(item);
1061 }
1062 }
1063
1064 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 (
)))))))
);
1065}
1066
1067void factorize_cb (CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)),
1068 MathButtons *buttons)
1069{
1070 math_equation_factorize(buttons->priv->equation);
1071}
1072
1073
1074void digit_cb (CtkWidget *widget,
1075 MathButtons *buttons)
1076{
1077 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")))
);
1078}
1079
1080
1081void numeric_point_cb (CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)),
1082 MathButtons *buttons)
1083{
1084 math_equation_insert_numeric_point(buttons->priv->equation);
1085}
1086
1087
1088
1089void finc_cb (CtkWidget *widget,
1090 MathButtons *buttons)
1091{
1092 gchar *name;
1093
1094 name = g_object_get_data(G_OBJECT(widget)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), (((GType) ((20) << (2))))))))
, "finc_dialog");
1095 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
()))))))
);
1096 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
()))))))
);
1097}
1098
1099
1100void insert_character_code_cb (CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)),
1101 MathButtons *buttons)
1102{
1103 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
()))))))
);
1104}
1105
1106
1107void finc_activate_cb (CtkWidget *widget,
1108 MathButtons *buttons)
1109{
1110 gint dialog, field;
1111
1112 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")))
;
1113 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")))
;
1114
1115 if (finc_dialog_fields[dialog][field+1] == NULL((void*)0)) {
1116 CtkWidget *dialog_widget;
1117 dialog_widget = ctk_widget_get_toplevel(widget);
1118 if (ctk_widget_is_toplevel(dialog_widget)) {
1119 ctk_dialog_response(CTK_DIALOG(dialog_widget)((((CtkDialog*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((dialog_widget)), ((ctk_dialog_get_type ()))))))
,
1120 CTK_RESPONSE_OK);
1121 return;
1122 }
1123 }
1124 else {
1125 CtkWidget *next_widget;
1126 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
()))))))
;
1127 ctk_widget_grab_focus(next_widget);
1128 }
1129}
1130
1131
1132void finc_response_cb (CtkWidget *widget,
1133 gint response_id,
1134 MathButtons *buttons)
1135{
1136 int dialog;
1137 int i;
1138 MPNumber arg[4];
1139 CtkWidget *entry;
1140
1141 if (response_id != CTK_RESPONSE_OK)
1142 return;
1143
1144 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")))
;
1145
1146 for (i = 0; i < 4; i++) {
1147 if (finc_dialog_fields[dialog][i] == NULL((void*)0)) {
1148 continue;
1149 }
1150 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 (
)))))))
;
1151 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]);
1152 ctk_entry_set_text(CTK_ENTRY(entry)((((CtkEntry*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((entry)), ((ctk_entry_get_type ()))))))
, "0");
1153 }
1154 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 (
)))))))
);
1155
1156 do_finc_expression(buttons->priv->equation, dialog, &arg[0], &arg[1], &arg[2], &arg[3]);
1157}
1158
1159
1160void character_code_dialog_response_cb (CtkWidget *dialog,
1161 gint response_id,
1162 MathButtons *buttons)
1163{
1164 const gchar *text;
1165
1166 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
()))))))
);
1167
1168 if (response_id == CTK_RESPONSE_OK) {
1169 MPNumber x;
1170 int i = 0;
1171
1172 mp_set_from_integer(0, &x);
1173 while (TRUE(!(0))) {
1174 mp_add_integer(&x, text[i], &x);
1175 if (text[i+1]) {
1176 mp_shift(&x, 8, &x);
1177 i++;
1178 }
1179 else
1180 break;
1181 }
1182
1183 math_equation_insert_number(buttons->priv->equation, &x);
1184 }
1185
1186 ctk_widget_hide(dialog);
1187}
1188
1189
1190void character_code_dialog_activate_cb (CtkWidget *entry G_GNUC_UNUSED__attribute__ ((__unused__)),
1191 MathButtons *buttons)
1192{
1193 character_code_dialog_response_cb(buttons->priv->character_code_dialog, CTK_RESPONSE_OK, buttons);
1194}
1195
1196
1197gboolean character_code_dialog_delete_cb (CtkWidget *dialog,
1198 CdkEvent *event G_GNUC_UNUSED__attribute__ ((__unused__)),
1199 MathButtons *buttons)
1200{
1201 character_code_dialog_response_cb(dialog, CTK_RESPONSE_CANCEL, buttons);
1202 return TRUE(!(0));
1203}
1204
1205
1206gboolean bit_toggle_cb (CtkWidget *event_box,
1207 CdkEventButton *event G_GNUC_UNUSED__attribute__ ((__unused__)),
1208 MathButtons *buttons)
1209{
1210 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")))
);
1211 return TRUE(!(0));
1212}
1213
1214
1215static void
1216remove_trailing_spaces(MathButtons *buttons)
1217{
1218 CtkTextMark *insert_mark;
1219 CtkTextIter start, end;
1220 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
()))))))
);
1221 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);
1222 start = end;
1223 while (ctk_text_iter_backward_char(&start)) {
1224 if (!g_unichar_isspace(ctk_text_iter_get_char(&start)))
1225 break;
1226 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);
1227 }
1228}
1229
1230
1231void set_superscript_cb (CtkWidget *widget,
1232 MathButtons *buttons)
1233{
1234 if (ctk_toggle_button_get_active(CTK_TOGGLE_BUTTON(widget)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((ctk_toggle_button_get_type ()))))))
)) {
1235 math_equation_set_number_mode(buttons->priv->equation, SUPERSCRIPT);
1236 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
()))))))
)) {
1237 remove_trailing_spaces(buttons);
1238 }
1239 }
1240 else if (math_equation_get_number_mode(buttons->priv->equation) == SUPERSCRIPT)
1241 math_equation_set_number_mode(buttons->priv->equation, NORMAL);
1242}
1243
1244
1245void set_subscript_cb (CtkWidget *widget,
1246 MathButtons *buttons)
1247{
1248 if (ctk_toggle_button_get_active(CTK_TOGGLE_BUTTON(widget)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), ((ctk_toggle_button_get_type ()))))))
)) {
1249 math_equation_set_number_mode(buttons->priv->equation, SUBSCRIPT);
1250 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
()))))))
)) {
1251 remove_trailing_spaces(buttons);
1252 }
1253 }
1254 else if (math_equation_get_number_mode(buttons->priv->equation) == SUBSCRIPT)
1255 math_equation_set_number_mode(buttons->priv->equation, NORMAL);
1256}
1257
1258
1259static void
1260number_mode_changed_cb (MathEquation *equation,
1261 GParamSpec *spec G_GNUC_UNUSED__attribute__ ((__unused__)),
1262 MathButtons *buttons)
1263{
1264 GList *i;
1265 NumberMode mode;
1266
1267 mode = math_equation_get_number_mode(equation);
1268
1269 for (i = buttons->priv->superscript_toggles; i; i = i->next) {
1270 CtkWidget *widget = i->data;
1271 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);
1272 }
1273 for (i = buttons->priv->subscript_toggles; i; i = i->next) {
1274 CtkWidget *widget = i->data;
1275 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);
1276 }
1277}
1278
1279
1280static void
1281math_buttons_set_property(GObject *object,
1282 guint prop_id,
1283 const GValue *value,
1284 GParamSpec *pspec)
1285{
1286 MathButtons *self;
1287
1288 self = MATH_BUTTONS(object)((((MathButtons*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((object)), (math_buttons_get_type())))))
;
1289
1290 switch (prop_id) {
1291 case PROP_EQUATION:
1292 self->priv->equation = g_value_get_object(value);
1293 math_buttons_set_mode(self, self->priv->mode);
1294 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)
;
1295 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)
;
1296 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)
;
1297 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)
;
1298 number_mode_changed_cb(self->priv->equation, NULL((void*)0), self);
1299 display_changed_cb(self->priv->equation, NULL((void*)0), self);
1300 break;
1301 case PROP_MODE:
1302 math_buttons_set_mode(self, g_value_get_int(value));
1303 break;
1304 case PROP_PROGRAMMING_BASE:
1305 math_buttons_set_programming_base(self, g_value_get_int(value));
1306 break;
1307 default:
1308 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", 1308, ("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)
;
1309 break;
1310 }
1311}
1312
1313
1314static void
1315math_buttons_get_property(GObject *object,
1316 guint prop_id,
1317 GValue *value,
1318 GParamSpec *pspec)
1319{
1320 MathButtons *self;
1321
1322 self = MATH_BUTTONS(object)((((MathButtons*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((object)), (math_buttons_get_type())))))
;
1323
1324 switch (prop_id) {
1325 case PROP_EQUATION:
1326 g_value_set_object(value, self->priv->equation);
1327 break;
1328 case PROP_MODE:
1329 g_value_set_int(value, self->priv->mode);
1330 break;
1331 case PROP_PROGRAMMING_BASE:
1332 g_value_set_int(value, math_buttons_get_programming_base(self));
1333 break;
1334 default:
1335 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", 1335, ("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)
;
1336 break;
1337 }
1338}
1339
1340
1341static void
1342math_buttons_class_init(MathButtonsClass *klass)
1343{
1344 static GEnumValue button_mode_values[] =
1345 {
1346 {BASIC, "basic", "basic"},
1347 {ADVANCED, "advanced", "advanced"},
1348 {FINANCIAL, "financial", "financial"},
1349 {PROGRAMMING, "programming", "programming"},
1350 {0, NULL((void*)0), NULL((void*)0)}
1351 };
1352 GObjectClass *object_class = G_OBJECT_CLASS(klass)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((klass)), (((GType) ((20) << (2))))))))
;
1353
1354 object_class->get_property = math_buttons_get_property;
1355 object_class->set_property = math_buttons_set_property;
1356
1357 button_mode_type = g_enum_register_static("ButtonMode", button_mode_values);
1358
1359 g_object_class_install_property(object_class,
1360 PROP_EQUATION,
1361 g_param_spec_object("equation",
1362 "equation",
1363 "Equation being controlled",
1364 math_equation_get_type(),
1365 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
1366 g_object_class_install_property(object_class,
1367 PROP_MODE,
1368 g_param_spec_enum("mode",
1369 "mode",
1370 "Button mode",
1371 button_mode_type,
1372 BASIC,
1373 G_PARAM_READWRITE));
1374 g_object_class_install_property(object_class,
1375 PROP_PROGRAMMING_BASE,
1376 g_param_spec_int("programming-base",
1377 "programming-base",
1378 "Base to use in programming mode",
1379 2, 16, 10,
1380 G_PARAM_READWRITE));
1381}
1382
1383
1384static void
1385math_buttons_init(MathButtons *buttons)
1386{
1387 buttons->priv = math_buttons_get_instance_private (buttons);
1388 ctk_box_set_spacing(CTK_BOX(buttons)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((buttons)), ((ctk_box_get_type ()))))))
, 6);
1389 ctk_orientable_set_orientation (CTK_ORIENTABLE (buttons)((((CtkOrientable*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((buttons)), ((ctk_orientable_get_type ()))))))
,
1390 CTK_ORIENTATION_VERTICAL);
1391 buttons->priv->programming_base = 10;
1392 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)
;
1393}