File: | math-buttons.c |
Warning: | line 473, 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 gsize 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 (&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 ((&static_g_define_type_id ), (gsize) (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, GParamSpec *spec, MathButtons *buttons) |
430 | { |
431 | update_bit_panel(buttons); |
432 | } |
433 | |
434 | |
435 | static void |
436 | base_combobox_changed_cb(CtkWidget *combo, MathButtons *buttons) |
437 | { |
438 | gint value; |
439 | CtkTreeModel *model; |
440 | CtkTreeIter iter; |
441 | |
442 | model = ctk_combo_box_get_model(CTK_COMBO_BOX(combo)((((CtkComboBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((combo)), ((ctk_combo_box_get_type ()))))))); |
443 | 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); |
444 | ctk_tree_model_get(model, &iter, 1, &value, -1); |
445 | |
446 | math_buttons_set_programming_base(buttons, value); |
447 | } |
448 | |
449 | |
450 | static void |
451 | base_changed_cb(MathEquation *equation, GParamSpec *spec, MathButtons *buttons) |
452 | { |
453 | CtkTreeModel *model; |
454 | CtkTreeIter iter; |
455 | gboolean valid; |
456 | |
457 | if (buttons->priv->mode != PROGRAMMING) |
458 | return; |
459 | |
460 | 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 ()))))))); |
461 | valid = ctk_tree_model_get_iter_first(model, &iter); |
462 | buttons->priv->programming_base = math_equation_get_base(buttons->priv->equation); |
463 | |
464 | while (valid) { |
465 | gint v; |
466 | |
467 | ctk_tree_model_get(model, &iter, 1, &v, -1); |
468 | if (v == buttons->priv->programming_base) |
469 | break; |
470 | valid = ctk_tree_model_iter_next(model, &iter); |
471 | } |
472 | if (!valid) |
473 | valid = ctk_tree_model_get_iter_first(model, &iter); |
Value stored to 'valid' is never read | |
474 | |
475 | 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); |
476 | } |
477 | |
478 | |
479 | static CtkWidget * |
480 | load_mode(MathButtons *buttons, ButtonMode mode) |
481 | { |
482 | CtkBuilder *builder, **builder_ptr; |
483 | gint i; |
484 | gchar *name; |
485 | const gchar *path; |
486 | static gchar *objects[] = { "button_panel", "character_code_dialog", "currency_dialog", |
487 | "ctrm_dialog", "ddb_dialog", "fv_dialog", "gpm_dialog", |
488 | "pmt_dialog", "pv_dialog", "rate_dialog", "sln_dialog", |
489 | "syd_dialog", "term_dialog", "adjustment1", "adjustment2", NULL((void*)0) }; |
490 | CtkWidget *widget, **panel; |
491 | GError *error = NULL((void*)0); |
492 | |
493 | switch (mode) { |
494 | default: |
495 | case BASIC: |
496 | builder_ptr = &buttons->priv->basic_ui; |
497 | path = UI_BASIC_RESOURCE_PATH"/org/cafe/calculator/ui/buttons-basic.ui"; |
498 | panel = &buttons->priv->bas_panel; |
499 | break; |
500 | case ADVANCED: |
501 | builder_ptr = &buttons->priv->advanced_ui; |
502 | path = UI_ADVANCED_RESOURCE_PATH"/org/cafe/calculator/ui/buttons-advanced.ui"; |
503 | panel = &buttons->priv->adv_panel; |
504 | break; |
505 | case FINANCIAL: |
506 | builder_ptr = &buttons->priv->financial_ui; |
507 | path = UI_FINANCIAL_RESOURCE_PATH"/org/cafe/calculator/ui/buttons-financial.ui"; |
508 | panel = &buttons->priv->fin_panel; |
509 | break; |
510 | case PROGRAMMING: |
511 | builder_ptr = &buttons->priv->programming_ui; |
512 | path = UI_PROGRAMMING_RESOURCE_PATH"/org/cafe/calculator/ui/buttons-programming.ui"; |
513 | panel = &buttons->priv->prog_panel; |
514 | break; |
515 | } |
516 | |
517 | if (*panel) |
518 | goto out; |
519 | |
520 | builder = *builder_ptr = ctk_builder_new(); |
521 | // FIXME: Show dialog if failed to load |
522 | ctk_builder_add_objects_from_resource(builder, path, objects, &error); |
523 | if (error) { |
524 | g_warning("Error loading button UI: %s", error->message); |
525 | g_clear_error(&error); |
526 | } |
527 | *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 ())))))); |
528 | 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); |
529 | |
530 | /* Configure buttons */ |
531 | for (i = 0; button_data[i].widget_name != NULL((void*)0); i++) { |
532 | GObject *object; |
533 | CtkWidget *button; |
534 | |
535 | name = g_strdup_printf("calc_%s_button", button_data[i].widget_name); |
536 | object = ctk_builder_get_object(*builder_ptr, name); |
537 | g_free(name); |
538 | |
539 | if (!object) |
540 | continue; |
541 | button = CTK_WIDGET(object)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), ((ctk_widget_get_type ())))))); |
542 | if (button_data[i].data) |
543 | g_object_set_data(object, "calc_text", (gpointer) button_data[i].data); |
544 | |
545 | if (button_data[i].tooltip) |
546 | ctk_widget_set_tooltip_text(button, _(button_data[i].tooltip)gettext (button_data[i].tooltip)); |
547 | |
548 | atk_object_set_name(ctk_widget_get_accessible(button), button_data[i].widget_name); |
549 | } |
550 | |
551 | /* Set special button data */ |
552 | for (i = 0; i < 16; i++) { |
553 | CtkWidget *button; |
554 | |
555 | name = g_strdup_printf("calc_%d_button", i); |
556 | button = GET_WIDGET(builder, name)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object((builder), (name)))), ((ctk_widget_get_type ())))))); |
557 | if (button) { |
558 | gchar buffer[7]; |
559 | gint len; |
560 | |
561 | 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))); |
562 | len = g_unichar_to_utf8(math_equation_get_digit_text(buttons->priv->equation, i), buffer); |
563 | buffer[len] = '\0'; |
564 | ctk_button_set_label(CTK_BUTTON(button)((((CtkButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((button)), ((ctk_button_get_type ())))))), buffer); |
565 | } |
566 | g_free(name); |
567 | } |
568 | 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 ())))))); |
569 | if (widget) { |
570 | MpSerializer *serializer = math_equation_get_serializer(buttons->priv->equation); |
571 | gchar buffer[7]; |
572 | gint len; |
573 | len = g_unichar_to_utf8(mp_serializer_get_radix(serializer), buffer); |
574 | buffer[len] = '\0'; |
575 | ctk_button_set_label(CTK_BUTTON(widget)((((CtkButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_button_get_type ())))))), buffer); |
576 | } |
577 | |
578 | 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 ())))))); |
579 | if (widget) { |
580 | buttons->priv->superscript_toggles = g_list_append(buttons->priv->superscript_toggles, widget); |
581 | if (math_equation_get_number_mode(buttons->priv->equation) == SUPERSCRIPT) |
582 | 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))); |
583 | } |
584 | 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 ())))))); |
585 | if (widget) { |
586 | buttons->priv->subscript_toggles = g_list_append(buttons->priv->subscript_toggles, widget); |
587 | if (math_equation_get_number_mode(buttons->priv->equation) == SUBSCRIPT) |
588 | 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))); |
589 | } |
590 | |
591 | /* put the icon name "process-stop" in the buttons |
592 | button1, button3, button5, button7, button9, |
593 | button11, button13, button15, button17, button19 |
594 | taken from buttons-financial.ui */ |
595 | for (i = 1; i < 20; i++) { |
596 | if (i % 2) { |
597 | 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 ())))))); |
598 | 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; }))))) |
599 | ctk_button_set_image (CTK_BUTTON (widget)((((CtkButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_button_get_type ())))))), |
600 | ctk_image_new_from_icon_name ("process-stop", CTK_ICON_SIZE_BUTTON)); |
601 | } |
602 | } |
603 | |
604 | if (mode == PROGRAMMING) { |
605 | CtkListStore *model; |
606 | CtkTreeIter iter; |
607 | CtkCellRenderer *renderer; |
608 | |
609 | 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 ())))))); |
610 | 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 ())))))); |
611 | 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 ())))))); |
612 | |
613 | 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 ())))))); |
614 | for (i = 0; i < MAXBITS64; i++) { |
615 | name = g_strdup_printf("bit_label_%d", i); |
616 | 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 ())))))); |
617 | g_free(name); |
618 | name = g_strdup_printf("bit_eventbox_%d", i); |
619 | set_int_data(builder, name, "bit_index", i); |
620 | } |
621 | |
622 | 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 ())))))); |
623 | model = ctk_list_store_new(2, G_TYPE_STRING((GType) ((16) << (2))), G_TYPE_INT((GType) ((6) << (2))), G_TYPE_INT((GType) ((6) << (2)))); |
624 | 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 ()))))))); |
625 | ctk_list_store_append(CTK_LIST_STORE(model)((((CtkListStore*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((ctk_list_store_get_type ())))))), &iter); |
626 | ctk_list_store_set(CTK_LIST_STORE(model)((((CtkListStore*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), ((ctk_list_store_get_type ())))))), &iter, 0, |
627 | /* Number display mode combo: Binary, e.g. 10011010010₂ */ |
628 | _("Binary")gettext ("Binary"), 1, 2, -1); |
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: Octal, e.g. 2322₈ */ |
632 | _("Octal")gettext ("Octal"), 1, 8, -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: Decimal, e.g. 1234 */ |
636 | _("Decimal")gettext ("Decimal"), 1, 10, -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: Hexadecimal, e.g. 4D2₁₆ */ |
640 | _("Hexadecimal")gettext ("Hexadecimal"), 1, 16, -1); |
641 | renderer = ctk_cell_renderer_text_new(); |
642 | 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))); |
643 | 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); |
644 | |
645 | 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); |
646 | 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); |
647 | base_changed_cb(buttons->priv->equation, NULL((void*)0), buttons); |
648 | } |
649 | |
650 | /* Setup financial functions */ |
651 | if (mode == FINANCIAL) { |
652 | load_finc_dialogs(buttons); |
653 | |
654 | set_data(builder, "calc_finc_compounding_term_button", "finc_dialog", "ctrm_dialog"); |
655 | set_data(builder, "calc_finc_double_declining_depreciation_button", "finc_dialog", "ddb_dialog"); |
656 | set_data(builder, "calc_finc_future_value_button", "finc_dialog", "fv_dialog"); |
657 | set_data(builder, "calc_finc_gross_profit_margin_button", "finc_dialog", "gpm_dialog"); |
658 | set_data(builder, "calc_finc_periodic_payment_button", "finc_dialog", "pmt_dialog"); |
659 | set_data(builder, "calc_finc_present_value_button", "finc_dialog", "pv_dialog"); |
660 | set_data(builder, "calc_finc_periodic_interest_rate_button", "finc_dialog", "rate_dialog"); |
661 | set_data(builder, "calc_finc_straight_line_depreciation_button", "finc_dialog", "sln_dialog"); |
662 | set_data(builder, "calc_finc_sum_of_the_years_digits_depreciation_button", "finc_dialog", "syd_dialog"); |
663 | set_data(builder, "calc_finc_term_button", "finc_dialog", "term_dialog"); |
664 | } |
665 | |
666 | ctk_builder_connect_signals(builder, buttons); |
667 | |
668 | display_changed_cb(buttons->priv->equation, NULL((void*)0), buttons); |
669 | |
670 | out: |
671 | return *panel; |
672 | } |
673 | |
674 | |
675 | static void |
676 | converter_changed_cb(MathConverter *converter, MathButtons *buttons) |
677 | { |
678 | Unit *from_unit, *to_unit; |
679 | |
680 | math_converter_get_conversion(converter, &from_unit, &to_unit); |
681 | if (buttons->priv->mode == FINANCIAL) { |
682 | math_equation_set_source_currency(buttons->priv->equation, unit_get_name(from_unit)); |
683 | math_equation_set_target_currency(buttons->priv->equation, unit_get_name(to_unit)); |
684 | } |
685 | else { |
686 | math_equation_set_source_units(buttons->priv->equation, unit_get_name(from_unit)); |
687 | math_equation_set_target_units(buttons->priv->equation, unit_get_name(to_unit)); |
688 | } |
689 | |
690 | g_object_unref(from_unit); |
691 | g_object_unref(to_unit); |
692 | } |
693 | |
694 | |
695 | static void |
696 | load_buttons(MathButtons *buttons) |
697 | { |
698 | CtkWidget *panel; |
699 | |
700 | if (!ctk_widget_get_visible(CTK_WIDGET(buttons)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons)), ((ctk_widget_get_type ())))))))) |
701 | return; |
702 | |
703 | if (!buttons->priv->converter) { |
704 | buttons->priv->converter = math_converter_new(buttons->priv->equation); |
705 | 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); |
706 | 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); |
707 | } |
708 | |
709 | panel = load_mode(buttons, buttons->priv->mode); |
710 | if (buttons->priv->active_panel == panel) |
711 | return; |
712 | |
713 | /* Hide old buttons */ |
714 | if (buttons->priv->active_panel) |
715 | ctk_widget_hide(buttons->priv->active_panel); |
716 | |
717 | /* Load and display new buttons */ |
718 | buttons->priv->active_panel = panel; |
719 | if (panel) |
720 | ctk_widget_show(panel); |
721 | } |
722 | |
723 | |
724 | void |
725 | math_buttons_set_mode(MathButtons *buttons, ButtonMode mode) |
726 | { |
727 | 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); |
728 | |
729 | if (buttons->priv->mode == mode) |
730 | return; |
731 | |
732 | buttons->priv->mode = mode; |
733 | |
734 | if (mode == PROGRAMMING) |
735 | math_equation_set_base(buttons->priv->equation, buttons->priv->programming_base); |
736 | else |
737 | math_equation_set_base(buttons->priv->equation, 10); |
738 | |
739 | load_buttons(buttons); |
740 | |
741 | 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); |
742 | if (mode == ADVANCED) { |
743 | math_converter_set_category(buttons->priv->converter, NULL((void*)0)); |
744 | math_converter_set_conversion(buttons->priv->converter, |
745 | math_equation_get_source_units(buttons->priv->equation), |
746 | math_equation_get_target_units(buttons->priv->equation)); |
747 | } |
748 | else if (mode == FINANCIAL) { |
749 | math_converter_set_category(buttons->priv->converter, "currency"); |
750 | math_converter_set_conversion(buttons->priv->converter, |
751 | math_equation_get_source_currency(buttons->priv->equation), |
752 | math_equation_get_target_currency(buttons->priv->equation)); |
753 | } |
754 | |
755 | g_object_notify(G_OBJECT(buttons)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons)), (((GType) ((20) << (2)))))))), "mode"); |
756 | } |
757 | |
758 | |
759 | ButtonMode |
760 | math_buttons_get_mode(MathButtons *buttons) |
761 | { |
762 | return buttons->priv->mode; |
763 | } |
764 | |
765 | |
766 | void |
767 | math_buttons_set_programming_base(MathButtons *buttons, gint base) |
768 | { |
769 | 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); |
770 | |
771 | if (base == buttons->priv->programming_base) |
772 | return; |
773 | |
774 | buttons->priv->programming_base = base; |
775 | |
776 | g_settings_set_int(g_settings_var, "base", math_buttons_get_programming_base(buttons)); |
777 | |
778 | if (buttons->priv->mode == PROGRAMMING) |
779 | math_equation_set_base(buttons->priv->equation, base); |
780 | } |
781 | |
782 | |
783 | gint |
784 | math_buttons_get_programming_base(MathButtons *buttons) |
785 | { |
786 | 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); |
787 | return buttons->priv->programming_base; |
788 | } |
789 | |
790 | |
791 | void exponent_cb(CtkWidget *widget, MathButtons *buttons); |
792 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
793 | void |
794 | exponent_cb(CtkWidget *widget, MathButtons *buttons) |
795 | { |
796 | math_equation_insert_exponent(buttons->priv->equation); |
797 | } |
798 | |
799 | |
800 | void subtract_cb(CtkWidget *widget, MathButtons *buttons); |
801 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
802 | void |
803 | subtract_cb(CtkWidget *widget, MathButtons *buttons) |
804 | { |
805 | math_equation_insert_subtract(buttons->priv->equation); |
806 | } |
807 | |
808 | |
809 | void button_cb(CtkWidget *widget, MathButtons *buttons); |
810 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
811 | void |
812 | button_cb(CtkWidget *widget, MathButtons *buttons) |
813 | { |
814 | 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")); |
815 | } |
816 | |
817 | |
818 | void solve_cb(CtkWidget *widget, MathButtons *buttons); |
819 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
820 | void |
821 | solve_cb(CtkWidget *widget, MathButtons *buttons) |
822 | { |
823 | math_equation_solve(buttons->priv->equation); |
824 | } |
825 | |
826 | |
827 | void clear_cb(CtkWidget *widget, MathButtons *buttons); |
828 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
829 | void |
830 | clear_cb(CtkWidget *widget, MathButtons *buttons) |
831 | { |
832 | math_equation_clear(buttons->priv->equation); |
833 | } |
834 | |
835 | |
836 | void delete_cb(CtkWidget *widget, MathButtons *buttons); |
837 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
838 | void |
839 | delete_cb(CtkWidget *widget, MathButtons *buttons) |
840 | { |
841 | math_equation_delete(buttons->priv->equation); |
842 | } |
843 | |
844 | |
845 | void undo_cb(CtkWidget *widget, MathButtons *buttons); |
846 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
847 | void |
848 | undo_cb(CtkWidget *widget, MathButtons *buttons) |
849 | { |
850 | math_equation_undo(buttons->priv->equation); |
851 | } |
852 | |
853 | |
854 | static void |
855 | shift_cb(CtkWidget *widget, MathButtons *buttons) |
856 | { |
857 | 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")))); |
858 | } |
859 | |
860 | static void |
861 | popup_button_menu(CtkWidget *widget, CtkMenu *menu) |
862 | { |
863 | ctk_menu_popup_at_widget (menu, |
864 | widget, |
865 | CDK_GRAVITY_SOUTH_WEST, |
866 | CDK_GRAVITY_NORTH_WEST, |
867 | NULL((void*)0)); |
868 | } |
869 | |
870 | |
871 | void memory_cb(CtkWidget *widget, MathButtons *buttons); |
872 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
873 | void |
874 | memory_cb(CtkWidget *widget, MathButtons *buttons) |
875 | { |
876 | MathVariablePopup *popup; |
877 | CtkAllocation allocation; |
878 | gint x, y; |
879 | |
880 | popup = math_variable_popup_new(buttons->priv->equation); |
881 | 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 ()))))))); |
882 | |
883 | ctk_widget_get_allocation(widget, &allocation); |
884 | cdk_window_get_root_coords(ctk_widget_get_window(widget), allocation.x, allocation.y, &x, &y); |
885 | ctk_window_move(CTK_WINDOW(popup)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((popup)), ((ctk_window_get_type ())))))), x, y); |
886 | ctk_widget_show(CTK_WIDGET(popup)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((popup)), ((ctk_widget_get_type ()))))))); |
887 | } |
888 | |
889 | |
890 | void shift_left_cb(CtkWidget *widget, MathButtons *buttons); |
891 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
892 | void |
893 | shift_left_cb(CtkWidget *widget, MathButtons *buttons) |
894 | { |
895 | if (!buttons->priv->shift_left_menu) { |
896 | gint i; |
897 | CtkWidget *menu; |
898 | |
899 | menu = buttons->priv->shift_left_menu = ctk_menu_new(); |
900 | ctk_menu_set_reserve_toggle_size(CTK_MENU(menu)((((CtkMenu*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((menu)), ((ctk_menu_get_type ())))))), FALSE(0)); |
901 | |
902 | for (i = 1; i < 16; i++) { |
903 | CtkWidget *item, *label; |
904 | gchar *format, *text; |
905 | |
906 | if (i < 10) { |
907 | /* Left Shift Popup: Menu item to shift left by n places (n < 10) */ |
908 | format = ngettext("_%d place", "_%d places", i); |
909 | } |
910 | else { |
911 | /* Left Shift Popup: Menu item to shift left by n places (n >= 10) */ |
912 | format = ngettext("%d place", "%d places", i); |
913 | } |
914 | text = g_strdup_printf(format, i); |
915 | label = ctk_label_new_with_mnemonic(text); |
916 | |
917 | item = ctk_menu_item_new(); |
918 | 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))); |
919 | ctk_container_add(CTK_CONTAINER(item)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((item)), ((ctk_container_get_type ())))))), label); |
920 | ctk_menu_shell_append(CTK_MENU_SHELL(menu)((((CtkMenuShell*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((menu)), ((ctk_menu_shell_get_type ())))))), item); |
921 | g_signal_connect(item, "activate", G_CALLBACK(shift_cb), buttons)g_signal_connect_data ((item), ("activate"), (((GCallback) (shift_cb ))), (buttons), ((void*)0), (GConnectFlags) 0); |
922 | |
923 | ctk_widget_show(label); |
924 | ctk_widget_show(item); |
925 | g_free(text); |
926 | } |
927 | } |
928 | |
929 | 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 ()))))))); |
930 | } |
931 | |
932 | |
933 | void shift_right_cb(CtkWidget *widget, MathButtons *buttons); |
934 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
935 | void |
936 | shift_right_cb(CtkWidget *widget, MathButtons *buttons) |
937 | { |
938 | if (!buttons->priv->shift_right_menu) { |
939 | gint i; |
940 | CtkWidget *menu; |
941 | |
942 | menu = buttons->priv->shift_right_menu = ctk_menu_new(); |
943 | ctk_menu_set_reserve_toggle_size(CTK_MENU(menu)((((CtkMenu*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((menu)), ((ctk_menu_get_type ())))))), FALSE(0)); |
944 | |
945 | for (i = 1; i < 16; i++) { |
946 | CtkWidget *item, *label; |
947 | gchar *format, *text; |
948 | |
949 | if (i < 10) { |
950 | /* Right Shift Popup: Menu item to shift right by n places (n < 10) */ |
951 | format = ngettext("_%d place", "_%d places", i); |
952 | } |
953 | else { |
954 | /* Right Shift Popup: Menu item to shift right by n places (n >= 10) */ |
955 | format = ngettext("%d place", "%d places", i); |
956 | } |
957 | text = g_strdup_printf(format, i); |
958 | label = ctk_label_new_with_mnemonic(text); |
959 | |
960 | item = ctk_menu_item_new(); |
961 | 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))); |
962 | ctk_container_add(CTK_CONTAINER(item)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((item)), ((ctk_container_get_type ())))))), label); |
963 | ctk_menu_shell_append(CTK_MENU_SHELL(menu)((((CtkMenuShell*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((menu)), ((ctk_menu_shell_get_type ())))))), item); |
964 | g_signal_connect(item, "activate", G_CALLBACK(shift_cb), buttons)g_signal_connect_data ((item), ("activate"), (((GCallback) (shift_cb ))), (buttons), ((void*)0), (GConnectFlags) 0); |
965 | |
966 | ctk_widget_show(label); |
967 | ctk_widget_show(item); |
968 | g_free(text); |
969 | } |
970 | } |
971 | |
972 | 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 ()))))))); |
973 | } |
974 | |
975 | |
976 | static void |
977 | insert_function_cb(CtkWidget *widget, MathButtons *buttons) |
978 | { |
979 | 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")); |
980 | } |
981 | |
982 | |
983 | void function_cb(CtkWidget *widget, MathButtons *buttons); |
984 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
985 | void |
986 | function_cb(CtkWidget *widget, MathButtons *buttons) |
987 | { |
988 | if (!buttons->priv->function_menu) { |
989 | gint i; |
990 | CtkWidget *menu; |
991 | struct |
992 | { |
993 | gchar *name, *function; |
994 | } functions[] = |
995 | { |
996 | { /* Tooltip for the integer component button */ |
997 | N_("Integer Component")("Integer Component"), "int " }, |
998 | { /* Tooltip for the fractional component button */ |
999 | N_("Fractional Component")("Fractional Component"), "frac " }, |
1000 | { /* Tooltip for the round button */ |
1001 | N_("Round")("Round"), "round " }, |
1002 | { /* Tooltip for the floor button */ |
1003 | N_("Floor")("Floor"), "floor " }, |
1004 | { /* Tooltip for the ceiling button */ |
1005 | N_("Ceiling")("Ceiling"), "ceil " }, |
1006 | { /* Tooltip for the ceiling button */ |
1007 | N_("Sign")("Sign"), "sgn " }, |
1008 | { NULL((void*)0), NULL((void*)0) } |
1009 | }; |
1010 | |
1011 | menu = buttons->priv->function_menu = ctk_menu_new(); |
1012 | ctk_menu_set_reserve_toggle_size(CTK_MENU(menu)((((CtkMenu*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((menu)), ((ctk_menu_get_type ())))))), FALSE(0)); |
1013 | |
1014 | for (i = 0; functions[i].name != NULL((void*)0); i++) { |
1015 | CtkWidget *item; |
1016 | |
1017 | item = ctk_menu_item_new_with_label(_(functions[i].name)gettext (functions[i].name)); |
1018 | 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)); |
1019 | ctk_menu_shell_append(CTK_MENU_SHELL(menu)((((CtkMenuShell*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((menu)), ((ctk_menu_shell_get_type ())))))), item); |
1020 | 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); |
1021 | ctk_widget_show(item); |
1022 | } |
1023 | } |
1024 | |
1025 | 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 ()))))))); |
1026 | } |
1027 | |
1028 | static void |
1029 | insert_const_cb(CtkWidget *widget, MathButtons *buttons) |
1030 | { |
1031 | 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")); |
1032 | } |
1033 | |
1034 | |
1035 | void const_cb(CtkWidget *widget, MathButtons *buttons); |
1036 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
1037 | void |
1038 | const_cb(CtkWidget *widget, MathButtons *buttons) |
1039 | { |
1040 | if (!buttons->priv->const_menu) { |
1041 | gint i; |
1042 | CtkWidget *menu; |
1043 | struct |
1044 | { |
1045 | gchar *name, *constant, *tooltip; |
1046 | } constants[] = |
1047 | { |
1048 | { /* Tooltip for the c₀ component button */ |
1049 | N_("Velocity of Light")("Velocity of Light"), "c₀", N_("299,792,458 m/s")("299,792,458 m/s") }, |
1050 | { /* Tooltip for the μ₀ component button */ |
1051 | N_("Magnetic constant")("Magnetic constant"), "μ₀", N_("1.2566370614×10⁻⁶ N/A²")("1.2566370614×10⁻⁶ N/A²") }, |
1052 | { /* Tooltip for the ε₀ button */ |
1053 | N_("Electric constant")("Electric constant"), "ε₀", N_("8.85418782×10⁻¹² s⁴A²/m³kg")("8.85418782×10⁻¹² s⁴A²/m³kg") }, |
1054 | { /* Tooltip for the G button */ |
1055 | N_("Newtonian constant of gravitation")("Newtonian constant of gravitation"), "G", N_("6.67408×10⁻¹¹ m³/(s²kg)")("6.67408×10⁻¹¹ m³/(s²kg)") }, |
1056 | { /* Tooltip for the h button */ |
1057 | N_("Planck constant")("Planck constant"), "h", N_("6.62607004×10⁻³⁴ m²kg/s")("6.62607004×10⁻³⁴ m²kg/s") }, |
1058 | { /* Tooltip for the e button */ |
1059 | N_("Elementary charge")("Elementary charge"), "e", N_("1.6021766208(98)×10⁻¹⁹ C")("1.6021766208(98)×10⁻¹⁹ C") }, |
1060 | { /* Tooltip for the mₑ button */ |
1061 | N_("Electron mass")("Electron mass"), "mₑ", N_("9.10938356×10⁻³¹ kg")("9.10938356×10⁻³¹ kg") }, |
1062 | { /* Tooltip for the mₚ button */ |
1063 | N_("Proton mass")("Proton mass"), "mₚ", N_("1.672621898(21)×10⁻²⁷ kg")("1.672621898(21)×10⁻²⁷ kg") }, |
1064 | { /* Tooltip for the Nₐ button */ |
1065 | N_("Avogadro constant")("Avogadro constant"), "Nₐ", N_("6.02214086×10²³ mol⁻¹")("6.02214086×10²³ mol⁻¹") }, |
1066 | { NULL((void*)0), NULL((void*)0), NULL((void*)0) } |
1067 | }; |
1068 | |
1069 | menu = buttons->priv->const_menu = ctk_menu_new(); |
1070 | ctk_menu_set_reserve_toggle_size(CTK_MENU(menu)((((CtkMenu*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((menu)), ((ctk_menu_get_type ())))))), FALSE(0)); |
1071 | |
1072 | for (i = 0; constants[i].name != NULL((void*)0); i++) { |
1073 | CtkWidget *item; |
1074 | |
1075 | item = ctk_menu_item_new_with_label(_(constants[i].name)gettext (constants[i].name)); |
1076 | ctk_widget_set_tooltip_text(item, _(constants[i].tooltip)gettext (constants[i].tooltip)); |
1077 | 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)); |
1078 | ctk_menu_shell_append(CTK_MENU_SHELL(menu)((((CtkMenuShell*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((menu)), ((ctk_menu_shell_get_type ())))))), item); |
1079 | 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); |
1080 | ctk_widget_show(item); |
1081 | } |
1082 | } |
1083 | |
1084 | 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 ( )))))))); |
1085 | } |
1086 | |
1087 | void factorize_cb(CtkWidget *widget, MathButtons *buttons); |
1088 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
1089 | void |
1090 | factorize_cb(CtkWidget *widget, MathButtons *buttons) |
1091 | { |
1092 | math_equation_factorize(buttons->priv->equation); |
1093 | } |
1094 | |
1095 | |
1096 | void digit_cb(CtkWidget *widget, MathButtons *buttons); |
1097 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
1098 | void |
1099 | digit_cb(CtkWidget *widget, MathButtons *buttons) |
1100 | { |
1101 | 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")))); |
1102 | } |
1103 | |
1104 | |
1105 | void numeric_point_cb(CtkWidget *widget, MathButtons *buttons); |
1106 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
1107 | void |
1108 | numeric_point_cb(CtkWidget *widget, MathButtons *buttons) |
1109 | { |
1110 | math_equation_insert_numeric_point(buttons->priv->equation); |
1111 | } |
1112 | |
1113 | |
1114 | |
1115 | void finc_cb(CtkWidget *widget, MathButtons *buttons); |
1116 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
1117 | void |
1118 | finc_cb(CtkWidget *widget, MathButtons *buttons) |
1119 | { |
1120 | gchar *name; |
1121 | |
1122 | name = g_object_get_data(G_OBJECT(widget)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), (((GType) ((20) << (2)))))))), "finc_dialog"); |
1123 | 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 ()))))))); |
1124 | 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 ()))))))); |
1125 | } |
1126 | |
1127 | |
1128 | void insert_character_code_cb(CtkWidget *widget, MathButtons *buttons); |
1129 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
1130 | void |
1131 | insert_character_code_cb(CtkWidget *widget, MathButtons *buttons) |
1132 | { |
1133 | 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 ()))))))); |
1134 | } |
1135 | |
1136 | |
1137 | void finc_activate_cb(CtkWidget *widget, MathButtons *buttons); |
1138 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
1139 | void |
1140 | finc_activate_cb(CtkWidget *widget, MathButtons *buttons) |
1141 | { |
1142 | gint dialog, field; |
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 | 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"))); |
1146 | |
1147 | if (finc_dialog_fields[dialog][field+1] == NULL((void*)0)) { |
1148 | CtkWidget *dialog_widget; |
1149 | dialog_widget = ctk_widget_get_toplevel(widget); |
1150 | if (ctk_widget_is_toplevel(dialog_widget)) { |
1151 | ctk_dialog_response(CTK_DIALOG(dialog_widget)((((CtkDialog*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((dialog_widget)), ((ctk_dialog_get_type ())))))), |
1152 | CTK_RESPONSE_OK); |
1153 | return; |
1154 | } |
1155 | } |
1156 | else { |
1157 | CtkWidget *next_widget; |
1158 | 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 ())))))); |
1159 | ctk_widget_grab_focus(next_widget); |
1160 | } |
1161 | } |
1162 | |
1163 | |
1164 | void finc_response_cb(CtkWidget *widget, gint response_id, MathButtons *buttons); |
1165 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
1166 | void |
1167 | finc_response_cb(CtkWidget *widget, gint response_id, MathButtons *buttons) |
1168 | { |
1169 | int dialog; |
1170 | int i; |
1171 | MPNumber arg[4]; |
1172 | CtkWidget *entry; |
1173 | |
1174 | if (response_id != CTK_RESPONSE_OK) |
1175 | return; |
1176 | |
1177 | 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"))); |
1178 | |
1179 | for (i = 0; i < 4; i++) { |
1180 | if (finc_dialog_fields[dialog][i] == NULL((void*)0)) { |
1181 | continue; |
1182 | } |
1183 | 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 ( ))))))); |
1184 | 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]); |
1185 | ctk_entry_set_text(CTK_ENTRY(entry)((((CtkEntry*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((entry)), ((ctk_entry_get_type ())))))), "0"); |
1186 | } |
1187 | 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 ( )))))))); |
1188 | |
1189 | do_finc_expression(buttons->priv->equation, dialog, &arg[0], &arg[1], &arg[2], &arg[3]); |
1190 | } |
1191 | |
1192 | |
1193 | void character_code_dialog_response_cb(CtkWidget *dialog, gint response_id, MathButtons *buttons); |
1194 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
1195 | void |
1196 | character_code_dialog_response_cb(CtkWidget *dialog, gint response_id, MathButtons *buttons) |
1197 | { |
1198 | const gchar *text; |
1199 | |
1200 | 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 ()))))))); |
1201 | |
1202 | if (response_id == CTK_RESPONSE_OK) { |
1203 | MPNumber x; |
1204 | int i = 0; |
1205 | |
1206 | mp_set_from_integer(0, &x); |
1207 | while (TRUE(!(0))) { |
1208 | mp_add_integer(&x, text[i], &x); |
1209 | if (text[i+1]) { |
1210 | mp_shift(&x, 8, &x); |
1211 | i++; |
1212 | } |
1213 | else |
1214 | break; |
1215 | } |
1216 | |
1217 | math_equation_insert_number(buttons->priv->equation, &x); |
1218 | } |
1219 | |
1220 | ctk_widget_hide(dialog); |
1221 | } |
1222 | |
1223 | |
1224 | void character_code_dialog_activate_cb(CtkWidget *entry, MathButtons *buttons); |
1225 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
1226 | void |
1227 | character_code_dialog_activate_cb(CtkWidget *entry, MathButtons *buttons) |
1228 | { |
1229 | character_code_dialog_response_cb(buttons->priv->character_code_dialog, CTK_RESPONSE_OK, buttons); |
1230 | } |
1231 | |
1232 | |
1233 | gboolean character_code_dialog_delete_cb(CtkWidget *dialog, CdkEvent *event, MathButtons *buttons); |
1234 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
1235 | gboolean |
1236 | character_code_dialog_delete_cb(CtkWidget *dialog, CdkEvent *event, MathButtons *buttons) |
1237 | { |
1238 | character_code_dialog_response_cb(dialog, CTK_RESPONSE_CANCEL, buttons); |
1239 | return TRUE(!(0)); |
1240 | } |
1241 | |
1242 | |
1243 | gboolean bit_toggle_cb(CtkWidget *event_box, CdkEventButton *event, MathButtons *buttons); |
1244 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
1245 | gboolean |
1246 | bit_toggle_cb(CtkWidget *event_box, CdkEventButton *event, MathButtons *buttons) |
1247 | { |
1248 | 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")))); |
1249 | return TRUE(!(0)); |
1250 | } |
1251 | |
1252 | |
1253 | static void |
1254 | remove_trailing_spaces(MathButtons *buttons) |
1255 | { |
1256 | CtkTextMark *insert_mark; |
1257 | CtkTextIter start, end; |
1258 | 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 ()))))))); |
1259 | 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); |
1260 | start = end; |
1261 | while (ctk_text_iter_backward_char(&start)) { |
1262 | if (!g_unichar_isspace(ctk_text_iter_get_char(&start))) |
1263 | break; |
1264 | 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); |
1265 | } |
1266 | } |
1267 | |
1268 | |
1269 | void set_superscript_cb(CtkWidget *widget, MathButtons *buttons); |
1270 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
1271 | void |
1272 | set_superscript_cb(CtkWidget *widget, MathButtons *buttons) |
1273 | { |
1274 | if (ctk_toggle_button_get_active(CTK_TOGGLE_BUTTON(widget)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_toggle_button_get_type ())))))))) { |
1275 | math_equation_set_number_mode(buttons->priv->equation, SUPERSCRIPT); |
1276 | 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 ())))))))) { |
1277 | remove_trailing_spaces(buttons); |
1278 | } |
1279 | } |
1280 | else if (math_equation_get_number_mode(buttons->priv->equation) == SUPERSCRIPT) |
1281 | math_equation_set_number_mode(buttons->priv->equation, NORMAL); |
1282 | } |
1283 | |
1284 | |
1285 | void set_subscript_cb(CtkWidget *widget, MathButtons *buttons); |
1286 | G_MODULE_EXPORT__attribute__((visibility("default"))) |
1287 | void |
1288 | set_subscript_cb(CtkWidget *widget, MathButtons *buttons) |
1289 | { |
1290 | if (ctk_toggle_button_get_active(CTK_TOGGLE_BUTTON(widget)((((CtkToggleButton*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), ((ctk_toggle_button_get_type ())))))))) { |
1291 | math_equation_set_number_mode(buttons->priv->equation, SUBSCRIPT); |
1292 | 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 ())))))))) { |
1293 | remove_trailing_spaces(buttons); |
1294 | } |
1295 | } |
1296 | else if (math_equation_get_number_mode(buttons->priv->equation) == SUBSCRIPT) |
1297 | math_equation_set_number_mode(buttons->priv->equation, NORMAL); |
1298 | } |
1299 | |
1300 | |
1301 | static void |
1302 | number_mode_changed_cb(MathEquation *equation, GParamSpec *spec, MathButtons *buttons) |
1303 | { |
1304 | GList *i; |
1305 | NumberMode mode; |
1306 | |
1307 | mode = math_equation_get_number_mode(equation); |
1308 | |
1309 | for (i = buttons->priv->superscript_toggles; i; i = i->next) { |
1310 | CtkWidget *widget = i->data; |
1311 | 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); |
1312 | } |
1313 | for (i = buttons->priv->subscript_toggles; i; i = i->next) { |
1314 | CtkWidget *widget = i->data; |
1315 | 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); |
1316 | } |
1317 | } |
1318 | |
1319 | |
1320 | static void |
1321 | math_buttons_set_property(GObject *object, |
1322 | guint prop_id, |
1323 | const GValue *value, |
1324 | GParamSpec *pspec) |
1325 | { |
1326 | MathButtons *self; |
1327 | |
1328 | self = MATH_BUTTONS(object)((((MathButtons*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), (math_buttons_get_type()))))); |
1329 | |
1330 | switch (prop_id) { |
1331 | case PROP_EQUATION: |
1332 | self->priv->equation = g_value_get_object(value); |
1333 | math_buttons_set_mode(self, self->priv->mode); |
1334 | 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); |
1335 | 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); |
1336 | 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); |
1337 | 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); |
1338 | number_mode_changed_cb(self->priv->equation, NULL((void*)0), self); |
1339 | display_changed_cb(self->priv->equation, NULL((void*)0), self); |
1340 | break; |
1341 | case PROP_MODE: |
1342 | math_buttons_set_mode(self, g_value_get_int(value)); |
1343 | break; |
1344 | case PROP_PROGRAMMING_BASE: |
1345 | math_buttons_set_programming_base(self, g_value_get_int(value)); |
1346 | break; |
1347 | default: |
1348 | 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", 1348, ("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); |
1349 | break; |
1350 | } |
1351 | } |
1352 | |
1353 | |
1354 | static void |
1355 | math_buttons_get_property(GObject *object, |
1356 | guint prop_id, |
1357 | GValue *value, |
1358 | GParamSpec *pspec) |
1359 | { |
1360 | MathButtons *self; |
1361 | |
1362 | self = MATH_BUTTONS(object)((((MathButtons*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), (math_buttons_get_type()))))); |
1363 | |
1364 | switch (prop_id) { |
1365 | case PROP_EQUATION: |
1366 | g_value_set_object(value, self->priv->equation); |
1367 | break; |
1368 | case PROP_MODE: |
1369 | g_value_set_int(value, self->priv->mode); |
1370 | break; |
1371 | case PROP_PROGRAMMING_BASE: |
1372 | g_value_set_int(value, math_buttons_get_programming_base(self)); |
1373 | break; |
1374 | default: |
1375 | 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", 1375, ("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); |
1376 | break; |
1377 | } |
1378 | } |
1379 | |
1380 | |
1381 | static void |
1382 | math_buttons_class_init(MathButtonsClass *klass) |
1383 | { |
1384 | static GEnumValue button_mode_values[] = |
1385 | { |
1386 | {BASIC, "basic", "basic"}, |
1387 | {ADVANCED, "advanced", "advanced"}, |
1388 | {FINANCIAL, "financial", "financial"}, |
1389 | {PROGRAMMING, "programming", "programming"}, |
1390 | {0, NULL((void*)0), NULL((void*)0)} |
1391 | }; |
1392 | GObjectClass *object_class = G_OBJECT_CLASS(klass)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((klass)), (((GType) ((20) << (2)))))))); |
1393 | |
1394 | object_class->get_property = math_buttons_get_property; |
1395 | object_class->set_property = math_buttons_set_property; |
1396 | |
1397 | button_mode_type = g_enum_register_static("ButtonMode", button_mode_values); |
1398 | |
1399 | g_object_class_install_property(object_class, |
1400 | PROP_EQUATION, |
1401 | g_param_spec_object("equation", |
1402 | "equation", |
1403 | "Equation being controlled", |
1404 | math_equation_get_type(), |
1405 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); |
1406 | g_object_class_install_property(object_class, |
1407 | PROP_MODE, |
1408 | g_param_spec_enum("mode", |
1409 | "mode", |
1410 | "Button mode", |
1411 | button_mode_type, |
1412 | BASIC, |
1413 | G_PARAM_READWRITE)); |
1414 | g_object_class_install_property(object_class, |
1415 | PROP_PROGRAMMING_BASE, |
1416 | g_param_spec_int("programming-base", |
1417 | "programming-base", |
1418 | "Base to use in programming mode", |
1419 | 2, 16, 10, |
1420 | G_PARAM_READWRITE)); |
1421 | } |
1422 | |
1423 | |
1424 | static void |
1425 | math_buttons_init(MathButtons *buttons) |
1426 | { |
1427 | buttons->priv = math_buttons_get_instance_private (buttons); |
1428 | ctk_box_set_spacing(CTK_BOX(buttons)((((CtkBox*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons)), ((ctk_box_get_type ())))))), 6); |
1429 | ctk_orientable_set_orientation (CTK_ORIENTABLE (buttons)((((CtkOrientable*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((buttons)), ((ctk_orientable_get_type ())))))), |
1430 | CTK_ORIENTATION_VERTICAL); |
1431 | buttons->priv->programming_base = 10; |
1432 | 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); |
1433 | } |