[gcalctool/gcalctool-newui2] ...
- From: Robert Ancell <rancell src gnome org>
- To: svn-commits-list gnome org
- Subject: [gcalctool/gcalctool-newui2] ...
- Date: Tue, 30 Jun 2009 01:44:17 +0000 (UTC)
commit 43f9160f6cdfb585e660796240539f1262eb88e4
Author: Robert Ancell <robert ancell gmail com>
Date: Tue Jun 30 10:56:45 2009 +1000
...
data/gcalctool.ui | 43 +++++++------
src/gtk.c | 184 ++++++++++++++++++++++++++++++++++++++++++-----------
2 files changed, 169 insertions(+), 58 deletions(-)
---
diff --git a/data/gcalctool.ui b/data/gcalctool.ui
index 011fa93..c22f40b 100644
--- a/data/gcalctool.ui
+++ b/data/gcalctool.ui
@@ -282,13 +282,14 @@
<object class="GtkScrolledWindow" id="display_scroll">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="border_width">7</property>
<property name="hscrollbar_policy">automatic</property>
<property name="vscrollbar_policy">never</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTextView" id="displayitem">
<property name="visible">True</property>
- <property name="border_width">2</property>
+ <property name="border_width">1</property>
<property name="pixels_above_lines">8</property>
<property name="pixels_below_lines">8</property>
<property name="editable">False</property>
@@ -2398,7 +2399,7 @@
<property name="AtkObject::accessible-name" translatable="yes">Calculate result</property>
</object>
</child>
- <signal name="clicked" handler="button_cb"/>
+ <signal name="clicked" handler="solve_cb"/>
</object>
<packing>
<property name="left_attach">2</property>
@@ -2529,7 +2530,7 @@
<property name="AtkObject::accessible-name" translatable="yes">Clear</property>
</object>
</child>
- <signal name="clicked" handler="button_cb"/>
+ <signal name="clicked" handler="clear_cb"/>
</object>
<packing>
<property name="left_attach">4</property>
@@ -2641,7 +2642,7 @@
<property name="AtkObject::accessible-name" translatable="yes">Store to register</property>
</object>
</child>
- <signal name="clicked" handler="button_cb"/>
+ <signal name="clicked" handler="popup_cb"/>
<child>
<object class="GtkHBox" id="hbox20">
<property name="visible">True</property>
@@ -2695,7 +2696,7 @@
<property name="AtkObject::accessible-name" translatable="yes">Retrieve from register</property>
</object>
</child>
- <signal name="clicked" handler="button_cb"/>
+ <signal name="clicked" handler="popup_cb"/>
<child>
<object class="GtkHBox" id="hbox19">
<property name="visible">True</property>
@@ -2991,7 +2992,6 @@
<property name="border_width">3</property>
<property name="use_underline">True</property>
<property name="focus_on_click">False</property>
- <property name="yalign">0.43999999761581421</property>
<child internal-child="accessible">
<object class="AtkObject" id="calc_integer_portion_button-atkobject">
<property name="AtkObject::accessible-name" translatable="yes">Integer portion</property>
@@ -3033,7 +3033,7 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="calc_fractional_portion_button1">
+ <object class="GtkButton" id="calc_fractional_portion_button">
<property name="label" translatable="yes" comments="Integer portion button">frac</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -3041,7 +3041,6 @@
<property name="border_width">3</property>
<property name="use_underline">True</property>
<property name="focus_on_click">False</property>
- <property name="yalign">0.43999999761581421</property>
<child internal-child="accessible">
<object class="AtkObject" id="calc_fractional_portion_button1-atkobject">
<property name="AtkObject::accessible-name" translatable="yes">Integer portion</property>
@@ -3089,6 +3088,7 @@
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="border_width">3</property>
+ <property name="focus_on_click">False</property>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
@@ -3097,6 +3097,7 @@
<property name="use_markup">True</property>
</object>
</child>
+ <signal name="clicked" handler="set_subscript_cb"/>
</object>
<packing>
<property name="left_attach">3</property>
@@ -3113,6 +3114,7 @@
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="border_width">3</property>
+ <property name="focus_on_click">False</property>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
@@ -3120,6 +3122,7 @@
<property name="use_markup">True</property>
</object>
</child>
+ <signal name="clicked" handler="set_superscript_cb"/>
</object>
<packing>
<property name="left_attach">4</property>
@@ -3416,7 +3419,7 @@
<property name="receives_default">True</property>
<property name="border_width">3</property>
<property name="focus_on_click">False</property>
- <signal name="clicked" handler="button_cb"/>
+ <signal name="clicked" handler="popup_cb"/>
<child>
<object class="GtkHBox" id="hbox10">
<property name="visible">True</property>
@@ -3460,7 +3463,7 @@
<property name="receives_default">True</property>
<property name="border_width">3</property>
<property name="focus_on_click">False</property>
- <signal name="clicked" handler="button_cb"/>
+ <signal name="clicked" handler="popup_cb"/>
<child>
<object class="GtkHBox" id="hbox11">
<property name="visible">True</property>
@@ -3923,7 +3926,7 @@
<property name="AtkObject::accessible-description" translatable="yes">Straight-line depreciation [l]</property>
</object>
</child>
- <signal name="clicked" handler="button_cb"/>
+ <signal name="clicked" handler="finc_cb"/>
</object>
<packing>
<property name="left_attach">7</property>
@@ -3947,7 +3950,7 @@
<property name="AtkObject::accessible-description" translatable="yes">Periodic interest rate [T]</property>
</object>
</child>
- <signal name="clicked" handler="button_cb"/>
+ <signal name="clicked" handler="finc_cb"/>
</object>
<packing>
<property name="left_attach">6</property>
@@ -3971,7 +3974,7 @@
<property name="AtkObject::accessible-description" translatable="yes">Present value [p]</property>
</object>
</child>
- <signal name="clicked" handler="button_cb"/>
+ <signal name="clicked" handler="finc_cb"/>
</object>
<packing>
<property name="left_attach">5</property>
@@ -3995,7 +3998,7 @@
<property name="AtkObject::accessible-description" translatable="yes">Periodic payment [P]</property>
</object>
</child>
- <signal name="clicked" handler="button_cb"/>
+ <signal name="clicked" handler="finc_cb"/>
</object>
<packing>
<property name="left_attach">4</property>
@@ -4019,7 +4022,7 @@
<property name="AtkObject::accessible-description" translatable="yes">Future value [v]</property>
</object>
</child>
- <signal name="clicked" handler="button_cb"/>
+ <signal name="clicked" handler="finc_cb"/>
</object>
<packing>
<property name="left_attach">2</property>
@@ -4043,7 +4046,7 @@
<property name="AtkObject::accessible-description" translatable="yes">Gross Profit Margin [g]</property>
</object>
</child>
- <signal name="clicked" handler="button_cb"/>
+ <signal name="clicked" handler="finc_cb"/>
</object>
<packing>
<property name="left_attach">3</property>
@@ -4067,7 +4070,7 @@
<property name="AtkObject::accessible-description" translatable="yes">Double-declining depreciation [D]</property>
</object>
</child>
- <signal name="clicked" handler="button_cb"/>
+ <signal name="clicked" handler="finc_cb"/>
</object>
<packing>
<property name="left_attach">1</property>
@@ -4091,7 +4094,7 @@
<property name="AtkObject::accessible-description" translatable="yes">Compounding term [m]</property>
</object>
</child>
- <signal name="clicked" handler="button_cb"/>
+ <signal name="clicked" handler="finc_cb"/>
</object>
<packing>
<property name="x_options">GTK_EXPAND | GTK_SHRINK | GTK_FILL</property>
@@ -4113,7 +4116,7 @@
<property name="AtkObject::accessible-description" translatable="yes">Sum-of-the years'-digits depreciation [y]</property>
</object>
</child>
- <signal name="clicked" handler="button_cb"/>
+ <signal name="clicked" handler="finc_cb"/>
</object>
<packing>
<property name="left_attach">8</property>
@@ -4137,7 +4140,7 @@
<property name="AtkObject::accessible-description" translatable="yes">Payment period [t]</property>
</object>
</child>
- <signal name="clicked" handler="button_cb"/>
+ <signal name="clicked" handler="finc_cb"/>
</object>
<packing>
<property name="left_attach">9</property>
diff --git a/src/gtk.c b/src/gtk.c
index a7907b7..7454287 100644
--- a/src/gtk.c
+++ b/src/gtk.c
@@ -48,12 +48,69 @@
static const char *mode_names[] = { "BASIC", "ADVANCED", "FINANCIAL",
"SCIENTIFIC", "PROGRAMMING", NULL };
-#define MAX_ACCELERATORS 8
-struct button_widget {
- int function;
+typedef struct {
char *widget_name;
- guint accelerator_mods[MAX_ACCELERATORS];
- guint accelerator_keys[MAX_ACCELERATORS];
+ char *data;
+} ButtonData;
+
+static ButtonData button_data[] = {
+ {"0", "0"},
+ {"1", "1"},
+ {"2", "2"},
+ {"3", "3"},
+ {"4", "4"},
+ {"5", "5"},
+ {"6", "6"},
+ {"7", "7"},
+ {"8", "8"},
+ {"9", "9"},
+ {"a", "A"},
+ {"b", "B"},
+ {"c", "C"},
+ {"d", "D"},
+ {"e", "E"},
+ {"f", "F"},
+ {"pi", "Ï?"},
+ {"eulers_number", "e"},
+ {"random", "rand"},
+ {"ans", "ans"},
+ {"numeric_point", "."},
+ {"add", "+"},
+ {"subtract", "â??"},
+ {"multiply", "Ã?"},
+ {"divide", "÷"},
+ {"modulus_divide", "mod"},
+ {"x_pow_y", "^"},
+ {"exponential", "Ã?10^"},
+ {"percentage", "%"},
+ {"factorial", "!"},
+ {"abs", "|"},
+ {"root", "â??"},
+ {"logarithm", "log"},
+ {"natural_logarithm", "ln"},
+ {"sine", "sin"},
+ {"cosine", "cos"},
+ {"tangent", "tan"},
+ {"hyperbolic_sine", "sinh"},
+ {"hyperbolic_cosine", "cosh"},
+ {"hyperbolic_tangent", "tanh"},
+ {"inverse", "�¹"},
+ {"base_2", "â??"},
+ {"base_8", "â??"},
+ {"base_16", "â??â??"},
+ {"and", "and"},
+ {"or", "or"},
+ {"xor", "xor"},
+ {"xnor", "xnor"},
+ {"not", "not"},
+ {"integer_portion", "int"},
+ {"fractional_portion", "frac"},
+ {"ones_complement", "ones"},
+ {"twos_complement", "twos"},
+ {"trunc", "trunc"},
+ {"start_group", "("},
+ {"end_group", ")"},
+ {NULL, NULL}
};
/* Window titles dependant on mode */
@@ -143,6 +200,9 @@ typedef struct {
GtkWidget *sci_panel; /* Panel containing scientific mode widgets. */
GtkWidget *prog_panel; /* Panel containing programming mode widgets. */
+ GtkWidget *superscript_toggle;
+ GtkWidget *subscript_toggle;
+
/* Labels for popup menus */
GtkWidget *memory_store_labels[MAX_REGISTERS];
GtkWidget *memory_recall_labels[MAX_REGISTERS];
@@ -1055,6 +1115,24 @@ bit_toggle_cb(GtkWidget *event_box, GdkEventButton *event)
G_MODULE_EXPORT
void
+set_superscript_cb(GtkWidget *widget)
+{
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(X.subscript_toggle), FALSE);
+}
+
+
+G_MODULE_EXPORT
+void
+set_subscript_cb(GtkWidget *widget)
+{
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(X.superscript_toggle), FALSE);
+}
+
+
+G_MODULE_EXPORT
+void
menu_item_select_cb(GtkWidget *widget)
{
GtkStatusbar *statusbar = GTK_STATUSBAR(X.statusbar);
@@ -1183,45 +1261,66 @@ menu_pos_func(GtkMenu *menu, gint *x, gint *y,
G_MODULE_EXPORT
void
-button_cb(GtkWidget *widget, GdkEventButton *event)
+solve_cb(GtkWidget *widget, GdkEventButton *event)
+{
+ do_button(FN_CALCULATE, 0);
+}
+
+
+G_MODULE_EXPORT
+void
+clear_cb(GtkWidget *widget, GdkEventButton *event)
+{
+ do_button(FN_CLEAR, 0);
+}
+
+
+G_MODULE_EXPORT
+void
+finc_cb(GtkWidget *widget, GdkEventButton *event)
+{
+ do_finc(g_object_get_data(G_OBJECT(widget), "finc_dialog"));
+}
+
+
+G_MODULE_EXPORT
+void
+popup_cb(GtkWidget *widget, GdkEventButton *event)
{
- int function;
GtkWidget *menu;
GdkPoint loc;
- char* dialog;
-
- function = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "calc_function"));
- menu = (GtkWidget *)g_object_get_data(G_OBJECT(widget), "calc_menu");
- dialog = g_object_get_data(G_OBJECT(widget), "finc_dialog");
- if (menu == NULL && dialog == NULL) {
- do_button(function, 0);
- } else if (dialog != NULL) {
- do_finc(dialog);
- } else {
- /* If gcalctool is being driven by gok, the on-screen keyboard
- * assistive technology, it's possible that the event returned by
- * gtk_get_current_event() is NULL. If this is the case, we need
- * to fudge the popping up on the menu associated with this menu
- * button.
- */
-
- update_memory_menus();
-
- if (event == NULL) {
- gdk_window_get_origin(widget->window, &loc.x, &loc.y);
- loc.x += widget->allocation.x;
- loc.y += widget->allocation.y;
- gtk_menu_popup(GTK_MENU(menu), NULL, NULL, menu_pos_func,
- (gpointer) &loc, 0, gtk_get_current_event_time());
- } else if (event->button == 1) {
- gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
- event->button, event->time);
- }
+ /* If gcalctool is being driven by gok, the on-screen keyboard
+ * assistive technology, it's possible that the event returned by
+ * gtk_get_current_event() is NULL. If this is the case, we need
+ * to fudge the popping up on the menu associated with this menu
+ * button.
+ */
+
+ update_memory_menus();
+
+ menu = (GtkWidget *)g_object_get_data(G_OBJECT(widget), "calc_menu");
+ if (event == NULL) {
+ gdk_window_get_origin(widget->window, &loc.x, &loc.y);
+ loc.x += widget->allocation.x;
+ loc.y += widget->allocation.y;
+ gtk_menu_popup(GTK_MENU(menu), NULL, NULL, menu_pos_func,
+ (gpointer) &loc, 0, gtk_get_current_event_time());
+ } else if (event->button == 1) {
+ gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
+ event->button, event->time);
}
}
+G_MODULE_EXPORT
+void
+button_cb(GtkWidget *widget, GdkEventButton *event)
+{
+ do_text(g_object_get_data(G_OBJECT(widget), "calc_text"));
+}
+
+
/*static void
select_display_entry(int offset)
{
@@ -1594,14 +1693,23 @@ create_main_window()
X.fin_panel = GET_WIDGET("financial_panel");
X.bit_panel = GET_WIDGET("bit_panel");
X.statusbar = GET_WIDGET("statusbar");
+ X.superscript_toggle = GET_WIDGET("superscript_togglebutton");
+ X.subscript_toggle = GET_WIDGET("subscript_togglebutton");
X.preferences_dialog = GET_WIDGET("preferences_dialog");
+
+ /* Connect text to buttons */
+ for (i = 0; button_data[i].widget_name != NULL; i++) {
+ SNPRINTF(name, MAXLINE, "calc_%s_button", button_data[i].widget_name);
+ set_data(X.ui, name, "calc_text", button_data[i].data);
+ }
- /* Make popup buttons */
+ /* Connect menus to popup buttons */
set_data(X.ui, "calc_shift_left_button", "calc_menu", GET_WIDGET("left_shift_popup"));
set_data(X.ui, "calc_shift_right_button", "calc_menu", GET_WIDGET("right_shift_popup"));
-
set_data(X.ui, "calc_store_button", "calc_menu", GET_WIDGET("memory_store_popup"));
set_data(X.ui, "calc_recall_button", "calc_menu", GET_WIDGET("memory_recall_popup"));
+
+ /* Get labels from popup menus */
for (i = 0; i < MAX_REGISTERS; i++) {
SNPRINTF(name, MAXLINE, "store_menu_item%d", i);
widget = GET_WIDGET(name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]