[gcalctool/gcalctool-newui2] ...
- From: Robert Ancell <rancell src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gcalctool/gcalctool-newui2] ...
- Date: Tue, 22 Sep 2009 07:57:06 +0000 (UTC)
commit 40b5e56fa7fcc2379b795f63a5c038089f7908d0
Author: Robert Ancell <robert ancell gmail com>
Date: Tue Sep 22 17:56:45 2009 +1000
...
data/gcalctool.ui | 77 +++++++++--------------
src/get.h | 1 -
src/gtk.c | 180 ++++++++++++++++++++++++++++++++++++++++++++++-------
src/ui.h | 7 --
4 files changed, 186 insertions(+), 79 deletions(-)
---
diff --git a/data/gcalctool.ui b/data/gcalctool.ui
index c331da7..a00a0f4 100644
--- a/data/gcalctool.ui
+++ b/data/gcalctool.ui
@@ -27,28 +27,6 @@
<child type="submenu">
<object class="GtkMenu" id="menuitem1_menu">
<child>
- <object class="GtkImageMenuItem" id="quit_menu">
- <property name="label">gtk-quit</property>
- <property name="visible">True</property>
- <property name="tooltip_text" translatable="yes">Quit the calculator</property>
- <property name="use_underline">True</property>
- <property name="use_stock">True</property>
- <property name="accel_group">accelgroup1</property>
- <signal name="activate" handler="quit_cb"/>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="GtkMenuItem" id="edit_menu">
- <property name="visible">True</property>
- <property name="label" translatable="yes" comments="Edit menu">_Edit</property>
- <property name="use_underline">True</property>
- <child type="submenu">
- <object class="GtkMenu" id="edit_menu_menu">
- <child>
<object class="GtkImageMenuItem" id="copy_menu">
<property name="label">gtk-copy</property>
<property name="visible">True</property>
@@ -71,41 +49,33 @@
</object>
</child>
<child>
- <object class="GtkImageMenuItem" id="undo_menu">
- <property name="label" comments="Edit|Undo menu item">_Undo</property>
+ <object class="GtkSeparatorMenuItem" id="menuitem5">
<property name="visible">True</property>
- <property name="tooltip_text" translatable="yes">Undo</property>
- <property name="use_underline">True</property>
- <property name="use_stock">True</property>
- <property name="accel_group">accelgroup1</property>
- <accelerator key="Z" signal="activate" modifiers="GDK_CONTROL_MASK"/>
- <signal name="activate" handler="undo_cb"/>
</object>
</child>
<child>
- <object class="GtkImageMenuItem" id="redo_menu">
- <property name="label" comments="Edit|Redo menu item">_Redo</property>
+ <object class="GtkImageMenuItem" id="menuitem6">
+ <property name="label">gtk-preferences</property>
<property name="visible">True</property>
- <property name="tooltip_text" translatable="yes">Redo</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
- <property name="accel_group">accelgroup1</property>
- <accelerator key="Z" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
- <signal name="activate" handler="redo_cb"/>
+ <signal name="activate" handler="show_preferences_cb"/>
</object>
</child>
<child>
- <object class="GtkSeparatorMenuItem" id="menuitem5">
+ <object class="GtkSeparatorMenuItem" id="menuitem2">
<property name="visible">True</property>
</object>
</child>
<child>
- <object class="GtkImageMenuItem" id="menuitem6">
- <property name="label">gtk-preferences</property>
+ <object class="GtkImageMenuItem" id="quit_menu">
+ <property name="label">gtk-quit</property>
<property name="visible">True</property>
+ <property name="tooltip_text" translatable="yes">Quit the calculator</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
- <signal name="activate" handler="show_preferences_cb"/>
+ <property name="accel_group">accelgroup1</property>
+ <signal name="activate" handler="quit_cb"/>
</object>
</child>
</object>
@@ -4707,7 +4677,7 @@
<property name="icon-size">1</property>
</object>
<object class="GtkDialog" id="preferences_dialog">
- <property name="border_width">5</property>
+ <property name="border_width">8</property>
<property name="title" translatable="yes">Preferences</property>
<property name="type_hint">normal</property>
<property name="has_separator">False</property>
@@ -4717,10 +4687,11 @@
<object class="GtkVBox" id="dialog-vbox4">
<property name="visible">True</property>
<property name="orientation">vertical</property>
- <property name="spacing">18</property>
+ <property name="spacing">5</property>
<child>
<object class="GtkTable" id="table1">
<property name="visible">True</property>
+ <property name="border_width">5</property>
<property name="n_rows">4</property>
<property name="n_columns">2</property>
<property name="column_spacing">6</property>
@@ -4755,6 +4726,7 @@
<object class="GtkComboBox" id="angle_unit_combobox">
<property name="visible">True</property>
<property name="model">angle_unit_model</property>
+ <signal name="changed" handler="angle_unit_combobox_changed_cb"/>
</object>
<packing>
<property name="left_attach">1</property>
@@ -4765,6 +4737,7 @@
<object class="GtkComboBox" id="display_format_combobox">
<property name="visible">True</property>
<property name="model">display_format_model</property>
+ <signal name="changed" handler="display_format_combobox_changed_cb"/>
</object>
<packing>
<property name="left_attach">1</property>
@@ -4791,6 +4764,7 @@
<object class="GtkComboBox" id="word_size_combobox">
<property name="visible">True</property>
<property name="model">word_size_model</property>
+ <signal name="changed" handler="word_size_combobox_changed_cb"/>
</object>
<packing>
<property name="left_attach">1</property>
@@ -4810,13 +4784,14 @@
<property name="n_rows">3</property>
<property name="row_spacing">6</property>
<child>
- <object class="GtkCheckButton" id="checkbutton1">
+ <object class="GtkCheckButton" id="trailing_zeroes_check">
<property name="label" translatable="yes">Show trailing _zeroes</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
+ <signal name="toggled" handler="trailing_zeroes_check_toggled_cb"/>
</object>
<packing>
<property name="top_attach">1</property>
@@ -4824,13 +4799,14 @@
</packing>
</child>
<child>
- <object class="GtkCheckButton" id="checkbutton2">
+ <object class="GtkCheckButton" id="thousands_separator_check">
<property name="label" translatable="yes">Show _thousands separators</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
+ <signal name="toggled" handler="thousands_separator_check_toggled_cb"/>
</object>
<packing>
<property name="top_attach">2</property>
@@ -4847,7 +4823,7 @@
<property name="xalign">0</property>
<property name="label" translatable="yes">Show</property>
<property name="use_underline">True</property>
- <property name="mnemonic_widget">spinbutton1</property>
+ <property name="mnemonic_widget">decimal_places_spin</property>
</object>
<packing>
<property name="expand">False</property>
@@ -4855,10 +4831,12 @@
</packing>
</child>
<child>
- <object class="GtkSpinButton" id="spinbutton1">
+ <object class="GtkSpinButton" id="decimal_places_spin">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
+ <property name="adjustment">decimal_places_adjustment</property>
+ <signal name="value_changed" handler="decimal_places_spin_change_value_cb"/>
</object>
<packing>
<property name="expand">False</property>
@@ -4871,7 +4849,7 @@
<property name="xalign">0</property>
<property name="label" translatable="yes">decimal _places</property>
<property name="use_underline">True</property>
- <property name="mnemonic_widget">spinbutton1</property>
+ <property name="mnemonic_widget">decimal_places_spin</property>
</object>
<packing>
<property name="position">2</property>
@@ -4925,4 +4903,9 @@
</action-widgets>
</object>
<object class="GtkTextBuffer" id="info_buffer"/>
+ <object class="GtkAdjustment" id="decimal_places_adjustment">
+ <property name="upper">9</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">1</property>
+ </object>
</interface>
diff --git a/src/get.h b/src/get.h
index 06ce096..18accdf 100644
--- a/src/get.h
+++ b/src/get.h
@@ -27,7 +27,6 @@
#define R_ACCURACY "accuracy"
#define R_DISPLAY "result_format"
#define R_MODE "button_layout"
-#define R_REGS "showregisters"
#define R_TRIG "angle_units"
#define R_ZEROES "showzeroes"
#define R_TSEP "showthousands"
diff --git a/src/gtk.c b/src/gtk.c
index ea8144f..1eaa182 100644
--- a/src/gtk.c
+++ b/src/gtk.c
@@ -136,6 +136,15 @@ static char *finc_dialog_fields[][5] = {
#define GET_FINC_WIDGET(name) \
GTK_WIDGET(gtk_builder_get_object(X.financial, (name)))
+/* Calculator modes. */
+typedef enum {
+ BASIC,
+ ADVANCED,
+ FINANCIAL,
+ SCIENTIFIC,
+ PROGRAMMING
+} ModeType;
+
/* Gtk+/Xlib graphics object. */
typedef struct {
ModeType mode; /* Current calculator mode. */
@@ -320,8 +329,8 @@ position_popup(GtkWidget *base, GtkWidget *popup,
void
ui_set_undo_enabled(gboolean undo, gboolean redo)
{
- gtk_widget_set_sensitive(GET_WIDGET("undo_menu"), undo);
- gtk_widget_set_sensitive(GET_WIDGET("redo_menu"), redo);
+// gtk_widget_set_sensitive(GET_WIDGET("undo_menu"), undo);
+// gtk_widget_set_sensitive(GET_WIDGET("redo_menu"), redo);
}
@@ -402,7 +411,7 @@ do_finc(char* dialog)
gtk_widget_hide(GTK_WIDGET(GET_FINC_WIDGET(dialog)));
}
-void
+static void
ui_set_mode(ModeType mode)
{
GtkWidget *menu;
@@ -535,8 +544,8 @@ ui_set_error_state(gboolean error)
gtk_widget_set_sensitive(GET_WIDGET("copy_menu"), !v->error);
gtk_widget_set_sensitive(GET_WIDGET("paste_menu"), !v->error);
- gtk_widget_set_sensitive(GET_WIDGET("undo_menu"), !v->error);
- gtk_widget_set_sensitive(GET_WIDGET("redo_menu"), !v->error);
+// gtk_widget_set_sensitive(GET_WIDGET("undo_menu"), !v->error);
+// gtk_widget_set_sensitive(GET_WIDGET("redo_menu"), !v->error);
gtk_widget_set_sensitive(GET_WIDGET("view_basic_menu"), !v->error);
gtk_widget_set_sensitive(GET_WIDGET("view_advanced_menu"), !v->error);
gtk_widget_set_sensitive(GET_WIDGET("view_financial_menu"), !v->error);
@@ -1433,7 +1442,7 @@ create_main_window()
set_data(X.ui, "calc_finc_term_button", "finc_dialog", "term_dialog");
/* Configuration dialog */
-
+
widget = GET_WIDGET("angle_unit_combobox");
renderer = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), renderer, TRUE);
@@ -1476,53 +1485,176 @@ ui_init(int *argc, char ***argv)
}
+G_MODULE_EXPORT
+void
+angle_unit_combobox_changed_cb(GtkWidget *combo)
+{
+ const gchar *value;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+
+ model = gtk_combo_box_get_model(GTK_COMBO_BOX(combo));
+ gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter);
+ gtk_tree_model_get(model, &iter, 1, &value, -1);
+
+ set_resource(R_TRIG, value);
+}
+
+
+G_MODULE_EXPORT
+void
+display_format_combobox_changed_cb(GtkWidget *combo)
+{
+ const gchar *value;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+
+ model = gtk_combo_box_get_model(GTK_COMBO_BOX(combo));
+ gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter);
+ gtk_tree_model_get(model, &iter, 1, &value, -1);
+
+ set_resource(R_DISPLAY, value);
+}
+
+
+G_MODULE_EXPORT
+void
+word_size_combobox_changed_cb(GtkWidget *combo)
+{
+ gint value;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+
+ model = gtk_combo_box_get_model(GTK_COMBO_BOX(combo));
+ gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter);
+ gtk_tree_model_get(model, &iter, 1, &value, -1);
+
+ set_int_resource(R_WORDLEN, value);
+}
+
+
+G_MODULE_EXPORT
+void
+decimal_places_spin_change_value_cb(GtkWidget *spin)
+{
+ gint value = 0;
+
+ value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
+
+ set_int_resource(R_ACCURACY, value);
+}
+
+
+G_MODULE_EXPORT
+void
+thousands_separator_check_toggled_cb(GtkWidget *check)
+{
+ gboolean value;
+
+ value = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check));
+
+ set_boolean_resource(R_TSEP, value);
+}
+
+
+G_MODULE_EXPORT
+void
+trailing_zeroes_check_toggled_cb(GtkWidget *check)
+{
+ gboolean value;
+
+ value = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check));
+
+ set_boolean_resource(R_ZEROES, value);
+}
+
+
static void
-set_combo_box_from_config(const gchar *name, const gchar *key_name)
+set_combo_box_from_config(const gchar *name, const gchar *key_name, GType key_type)
{
GtkWidget *combo;
GtkTreeModel *model;
- gchar *key_value;
+ gchar *str_key_value = NULL;
+ int int_key_value;
GtkTreeIter iter;
gboolean valid;
combo = GET_WIDGET(name);
model = gtk_combo_box_get_model(GTK_COMBO_BOX(combo));
+ valid = gtk_tree_model_get_iter_first(model, &iter);
- key_value = get_resource(key_name);
- printf("'%s' '%s'\n", key_name, key_value);
- valid = key_value && gtk_tree_model_get_iter_first(model, &iter);
+ switch (key_type)
+ {
+ case G_TYPE_STRING:
+ str_key_value = get_resource(key_name);
+ if (!str_key_value)
+ valid = FALSE;
+ break;
+ case G_TYPE_INT:
+ if (!get_int_resource(key_name, &int_key_value))
+ valid = FALSE;
+ break;
+ default:
+ break;
+ }
+
while (valid) {
- GValue value = {0};
+ gchar *str_value;
+ gint int_value;
+ gboolean matched = FALSE;
- gtk_tree_model_get_value(model, &iter, 1, &value);
- printf("'%s' '%s'\n", g_value_get_string(&value), key_value);
- if (strcmp(g_value_get_string(&value), key_value) == 0) {
- printf("%s->%s\n", name, key_value);
- g_value_unset(&value);
+ switch (key_type)
+ {
+ case G_TYPE_STRING:
+ gtk_tree_model_get(model, &iter, 1, &str_value, -1);
+ matched = strcmp(str_value, str_key_value) == 0;
+ break;
+ case G_TYPE_INT:
+ gtk_tree_model_get(model, &iter, 1, &int_value, -1);
+ matched = int_value == int_key_value;
+ break;
+ default:
break;
}
- g_value_unset(&value);
+
+ if (matched)
+ break;
+
valid = gtk_tree_model_iter_next(model, &iter);
}
if (!valid)
valid = gtk_tree_model_get_iter_first(model, &iter);
-
- gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo), &iter);
- g_free(key_value);
+ gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo), &iter);
+
+ g_free(str_key_value);
}
void
ui_load(void)
{
+ int value;
+
/* Create main gcalctool window. */
create_main_window();
ui_set_undo_enabled(FALSE, FALSE);
- set_combo_box_from_config("angle_unit_combobox", R_TRIG);
- set_combo_box_from_config("display_format_combobox", R_DISPLAY);
- //set_combo_box_from_config("word_size_combobox", R_WORDLEN);
+ set_combo_box_from_config("angle_unit_combobox", R_TRIG, G_TYPE_STRING);
+ set_combo_box_from_config("display_format_combobox", R_DISPLAY, G_TYPE_STRING);
+ set_combo_box_from_config("word_size_combobox", R_WORDLEN, G_TYPE_INT);
+
+ if (!get_int_resource(R_ACCURACY, &value))
+ value = 9;
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(GET_OBJECT("decimal_places_spin")), value);
+
+ if (!get_boolean_resource(R_TSEP, &value))
+ value = FALSE;
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(GET_OBJECT("thousands_separator_check")), value);
+
+ if (!get_boolean_resource(R_ZEROES, &value))
+ value = FALSE;
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(GET_OBJECT("trailing_zeroes_check")), value);
}
diff --git a/src/ui.h b/src/ui.h
index d66470c..9efbd79 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -27,13 +27,6 @@
#include "calctool.h"
-/* Calculator modes. */
-typedef enum { BASIC,
- ADVANCED,
- FINANCIAL,
- SCIENTIFIC,
- PROGRAMMING } ModeType;
-
void ui_init(int *argc, char ***argv);
void ui_load(void);
void ui_start(void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]