[gcalctool/gcalctool-newui2] ...



commit 1620d1015ad896b90ba34a9a6b5487384571ba3e
Author: Robert Ancell <robert ancell gmail com>
Date:   Thu Jul 2 14:54:58 2009 +1000

    ...

 data/gcalctool.ui |  140 +++++++++++++++++++--------------------------------
 src/financial.h   |    3 +-
 src/gtk.c         |  144 ++++++++++++++++++++++++++++++++++++++++++++++------
 src/unittest.c    |   30 +++++++++++-
 4 files changed, 210 insertions(+), 107 deletions(-)
---
diff --git a/data/gcalctool.ui b/data/gcalctool.ui
index 4687c73..1600c85 100644
--- a/data/gcalctool.ui
+++ b/data/gcalctool.ui
@@ -12,6 +12,7 @@
     <child>
       <object class="GtkVBox" id="window_vbox">
         <property name="visible">True</property>
+        <property name="orientation">vertical</property>
         <property name="spacing">6</property>
         <child>
           <object class="GtkMenuBar" id="menubar">
@@ -2123,7 +2124,6 @@
                 <property name="visible">True</property>
                 <property name="n_rows">4</property>
                 <property name="n_columns">5</property>
-                <property name="homogeneous">True</property>
                 <child>
                   <object class="GtkButton" id="calc_4_button">
                     <property name="label" translatable="yes" comments="Numeric 4 button">4</property>
@@ -2630,7 +2630,6 @@
                 <property name="visible">True</property>
                 <property name="n_rows">4</property>
                 <property name="n_columns">5</property>
-                <property name="homogeneous">True</property>
                 <child>
                   <object class="GtkButton" id="calc_store_button">
                     <property name="visible">True</property>
@@ -3172,7 +3171,6 @@
                 <property name="visible">True</property>
                 <property name="n_rows">2</property>
                 <property name="n_columns">10</property>
-                <property name="homogeneous">True</property>
                 <child>
                   <object class="GtkButton" id="calc_d_button">
                     <property name="label" translatable="yes" comments="Hexadecimal digit D button">D</property>
@@ -3624,7 +3622,6 @@
             <child>
               <object class="GtkTable" id="si_panel">
                 <property name="n_columns">10</property>
-                <property name="homogeneous">True</property>
                 <child>
                   <object class="GtkButton" id="calc_si_kilo_button">
                     <property name="label" translatable="yes">k</property>
@@ -3783,7 +3780,6 @@
               <object class="GtkTable" id="scientific_panel">
                 <property name="visible">True</property>
                 <property name="n_columns">10</property>
-                <property name="homogeneous">True</property>
                 <child>
                   <object class="GtkButton" id="calc_tangent_button">
                     <property name="label" translatable="yes">tan</property>
@@ -3911,7 +3907,6 @@
               <object class="GtkTable" id="financial_panel">
                 <property name="visible">True</property>
                 <property name="n_columns">10</property>
-                <property name="homogeneous">True</property>
                 <child>
                   <object class="GtkButton" id="calc_finc_straight_line_depreciation_button">
                     <property name="label" translatable="yes" comments="Calculates the straight-line depreciation of an asset for one period. The depreciable cost is cost - salvage. The straight-line method of depreciation divides the depreciable cost evenly over the useful life of an asset. The useful life is the number of periods, typically years, over which an asset is depreciated. See also: http://en.wikipedia.org/wiki/Depreciation";>Sln</property>
@@ -4431,32 +4426,6 @@
       </object>
     </child>
   </object>
-  <object class="GtkListStore" id="numeric_base_model">
-    <columns>
-      <!-- column-name label -->
-      <column type="gchararray"/>
-      <!-- column-name base -->
-      <column type="gint"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">Binary</col>
-        <col id="1">2</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Octal</col>
-        <col id="1">8</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Decimal</col>
-        <col id="1">10</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Hexadecimal</col>
-        <col id="1">16</col>
-      </row>
-    </data>
-  </object>
   <object class="GtkListStore" id="angle_unit_model">
     <columns>
       <!-- column-name label -->
@@ -4488,16 +4457,28 @@
     </columns>
     <data>
       <row>
-        <col id="0" translatable="yes">Fixed precision</col>
-        <col id="1" translatable="yes">fixed</col>
+        <col id="0" translatable="yes">Decimal</col>
+        <col id="1">decimal</col>
       </row>
       <row>
         <col id="0" translatable="yes">Scientific</col>
-        <col id="1" translatable="yes">scientific</col>
+        <col id="1">scientific</col>
       </row>
       <row>
         <col id="0" translatable="yes">Engineering</col>
-        <col id="1" translatable="yes">engineering</col>
+        <col id="1">engineering</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Binary</col>
+        <col id="1">binary</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Octal</col>
+        <col id="1">octal</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Hexadecimal</col>
+        <col id="1">hexadecimal</col>
       </row>
     </data>
   </object>
@@ -4540,10 +4521,12 @@
     <child internal-child="vbox">
       <object class="GtkVBox" id="dialog-vbox2">
         <property name="visible">True</property>
+        <property name="orientation">vertical</property>
         <child>
           <object class="GtkVBox" id="vbox2">
             <property name="visible">True</property>
             <property name="border_width">5</property>
+            <property name="orientation">vertical</property>
             <property name="spacing">6</property>
             <child>
               <object class="GtkLabel" id="label51">
@@ -4801,6 +4784,7 @@
     <child internal-child="vbox">
       <object class="GtkVBox" id="dialog-vbox3">
         <property name="visible">True</property>
+        <property name="orientation">vertical</property>
         <child>
           <object class="GtkHBox" id="hbox21">
             <property name="visible">True</property>
@@ -4907,35 +4891,20 @@
         <child>
           <object class="GtkTable" id="table1">
             <property name="visible">True</property>
-            <property name="n_rows">7</property>
+            <property name="n_rows">6</property>
             <property name="n_columns">3</property>
             <property name="column_spacing">6</property>
             <property name="row_spacing">6</property>
             <child>
-              <object class="GtkLabel" id="label1">
-                <property name="visible">True</property>
-                <property name="xalign">0</property>
-                <property name="label" translatable="yes">Numeric _base:</property>
-                <property name="use_underline">True</property>
-                <property name="mnemonic_widget">combobox1</property>
-              </object>
-              <packing>
-                <property name="right_attach">2</property>
-                <property name="x_options">GTK_FILL</property>
-              </packing>
-            </child>
-            <child>
               <object class="GtkLabel" id="label2">
                 <property name="visible">True</property>
                 <property name="xalign">0</property>
                 <property name="label" translatable="yes">_Angle units:</property>
                 <property name="use_underline">True</property>
-                <property name="mnemonic_widget">combobox2</property>
+                <property name="mnemonic_widget">angle_unit_combobox</property>
               </object>
               <packing>
                 <property name="right_attach">2</property>
-                <property name="top_attach">1</property>
-                <property name="bottom_attach">2</property>
                 <property name="x_options">GTK_FILL</property>
               </packing>
             </child>
@@ -4945,47 +4914,35 @@
                 <property name="xalign">0</property>
                 <property name="label" translatable="yes">Display _Format:</property>
                 <property name="use_underline">True</property>
-                <property name="mnemonic_widget">combobox3</property>
+                <property name="mnemonic_widget">display_format_combobox</property>
               </object>
               <packing>
                 <property name="right_attach">2</property>
-                <property name="top_attach">2</property>
-                <property name="bottom_attach">3</property>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">2</property>
                 <property name="x_options">GTK_FILL</property>
               </packing>
             </child>
             <child>
-              <object class="GtkComboBox" id="combobox1">
-                <property name="visible">True</property>
-                <property name="model">numeric_base_model</property>
-              </object>
-              <packing>
-                <property name="left_attach">2</property>
-                <property name="right_attach">3</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkComboBox" id="combobox2">
+              <object class="GtkComboBox" id="angle_unit_combobox">
                 <property name="visible">True</property>
                 <property name="model">angle_unit_model</property>
               </object>
               <packing>
                 <property name="left_attach">2</property>
                 <property name="right_attach">3</property>
-                <property name="top_attach">1</property>
-                <property name="bottom_attach">2</property>
               </packing>
             </child>
             <child>
-              <object class="GtkComboBox" id="combobox3">
+              <object class="GtkComboBox" id="display_format_combobox">
                 <property name="visible">True</property>
                 <property name="model">display_format_model</property>
               </object>
               <packing>
                 <property name="left_attach">2</property>
                 <property name="right_attach">3</property>
-                <property name="top_attach">2</property>
-                <property name="bottom_attach">3</property>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">2</property>
               </packing>
             </child>
             <child>
@@ -4999,8 +4956,8 @@
               <packing>
                 <property name="left_attach">1</property>
                 <property name="right_attach">2</property>
-                <property name="top_attach">3</property>
-                <property name="bottom_attach">4</property>
+                <property name="top_attach">2</property>
+                <property name="bottom_attach">3</property>
                 <property name="x_options">GTK_FILL</property>
               </packing>
             </child>
@@ -5010,8 +4967,8 @@
                 <property name="label" translatable="yes">    </property>
               </object>
               <packing>
-                <property name="top_attach">3</property>
-                <property name="bottom_attach">5</property>
+                <property name="top_attach">2</property>
+                <property name="bottom_attach">4</property>
                 <property name="x_options">GTK_FILL</property>
               </packing>
             </child>
@@ -5024,8 +4981,8 @@
               <packing>
                 <property name="left_attach">2</property>
                 <property name="right_attach">3</property>
-                <property name="top_attach">3</property>
-                <property name="bottom_attach">4</property>
+                <property name="top_attach">2</property>
+                <property name="bottom_attach">3</property>
               </packing>
             </child>
             <child>
@@ -5038,8 +4995,8 @@
               </object>
               <packing>
                 <property name="right_attach">2</property>
-                <property name="top_attach">6</property>
-                <property name="bottom_attach">7</property>
+                <property name="top_attach">5</property>
+                <property name="bottom_attach">6</property>
                 <property name="x_options">GTK_FILL</property>
               </packing>
             </child>
@@ -5051,8 +5008,8 @@
               <packing>
                 <property name="left_attach">2</property>
                 <property name="right_attach">3</property>
-                <property name="top_attach">6</property>
-                <property name="bottom_attach">7</property>
+                <property name="top_attach">5</property>
+                <property name="bottom_attach">6</property>
               </packing>
             </child>
             <child>
@@ -5067,8 +5024,8 @@
               <packing>
                 <property name="left_attach">1</property>
                 <property name="right_attach">3</property>
-                <property name="top_attach">4</property>
-                <property name="bottom_attach">5</property>
+                <property name="top_attach">3</property>
+                <property name="bottom_attach">4</property>
               </packing>
             </child>
             <child>
@@ -5082,10 +5039,19 @@
               </object>
               <packing>
                 <property name="right_attach">3</property>
-                <property name="top_attach">5</property>
-                <property name="bottom_attach">6</property>
+                <property name="top_attach">4</property>
+                <property name="bottom_attach">5</property>
               </packing>
             </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
           </object>
           <packing>
             <property name="position">1</property>
@@ -5097,7 +5063,7 @@
             <property name="layout_style">end</property>
             <child>
               <object class="GtkButton" id="button1">
-                <property name="label" translatable="yes">gtk-close</property>
+                <property name="label">gtk-close</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
diff --git a/src/financial.h b/src/financial.h
index cf42055..0c95cc1 100644
--- a/src/financial.h
+++ b/src/financial.h
@@ -35,8 +35,7 @@ enum finc_dialogs {
     FINC_RATE_DIALOG,
     FINC_SLN_DIALOG,
     FINC_SYD_DIALOG,
-    FINC_TERM_DIALOG,
-    FINC_NUM_DIALOGS,
+    FINC_TERM_DIALOG
 };
 
 #endif /* FINANCIAL_H */
diff --git a/src/gtk.c b/src/gtk.c
index c885157..9d31824 100644
--- a/src/gtk.c
+++ b/src/gtk.c
@@ -142,7 +142,7 @@ static char *hostname_titles[] = {
 };
 
 /* The names of each field in the dialogs for the financial functions */
-static char *finc_dialog_fields[FINC_NUM_DIALOGS][5] = {
+static char *finc_dialog_fields[][5] = {
     {"ctrm_pint", "ctrm_fv",     "ctrm_pv",    NULL,         NULL},
     {"ddb_cost",  "ddb_life",    "ddb_period", NULL,         NULL},
     {"fv_pmt",    "fv_pint",     "fv_n",       NULL,         NULL},
@@ -153,6 +153,7 @@ static char *finc_dialog_fields[FINC_NUM_DIALOGS][5] = {
     {"sln_cost",  "sln_salvage", "sln_life",   NULL,         NULL},
     {"syd_cost",  "syd_salvage", "syd_life",   "syd_period", NULL},
     {"term_pmt",  "term_fv",     "term_pint",  NULL,         NULL},
+    {NULL,        NULL,          NULL,         NULL,         NULL}
 };
 
 #define UI_FILE      PACKAGE_UI_DIR "/gcalctool.ui"
@@ -384,6 +385,20 @@ ui_set_show_trailing_zeroes(gboolean visible)
 }
 
 
+void
+ui_set_base(int base)
+{
+    //FIXME: Obsolete
+}
+
+
+void
+ui_set_wordlen(int len)
+{
+    //FIXME: Obsolete
+}
+
+
 void 
 ui_set_undo_enabled(gboolean undo, gboolean redo)
 {
@@ -711,20 +726,6 @@ ui_beep()
 
 
 void
-ui_set_base(int base)
-{
-    //FIXME: Obsolete
-}
-
-
-void
-ui_set_wordlen(int len)
-{
-    //FIXME: Obsolete
-}
-
-
-void
 ui_set_registers_visible(gboolean visible)
 {
     GtkWidget *menu;
@@ -1035,7 +1036,7 @@ setup_finc_dialogs(void)
     set_int_data(X.financial, "syd_dialog", "finc_dialog", FINC_SYD_DIALOG);
     set_int_data(X.financial, "term_dialog", "finc_dialog", FINC_TERM_DIALOG);
     
-    for (i = 0; i < FINC_NUM_DIALOGS; i++) {
+    for (i = 0; finc_dialog_fields[i][0] != NULL; i++) {
         for (j = 0; finc_dialog_fields[i][j]; j++) {
             GObject *o;
             o = gtk_builder_get_object(X.financial, finc_dialog_fields[i][j]);
@@ -1717,7 +1718,7 @@ create_main_window()
     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);
@@ -1887,6 +1888,107 @@ ui_load(void)
         ui_set_registers_visible(boolval);
 }
 
+
+static void
+add_buttons_to_size_group()
+{
+    int i;
+    GtkSizeGroup *size_group;
+    
+    const char *button_names[] = {
+        "calc_finc_straight_line_depreciation_button",
+        "calc_finc_periodic_interest_rate_button",
+        "calc_finc_present_value_button",
+        "calc_finc_periodic_payment_button",
+        "calc_finc_future_value_button",
+        "calc_finc_gross_profit_margin_button",
+        "calc_finc_double_declining_depreciation_button",
+        "calc_finc_compounding_term_button",
+        "calc_finc_sum_of_the_years_digits_depreciation_button",
+        "calc_finc_term_button",
+        "calc_store_button",
+        "calc_recall_button",
+        "calc_pi_button",
+        "calc_modulus_divide_button",
+        "calc_root_button",
+        "calc_x_pow_y_button",
+        "calc_logarithm_button",
+        "calc_inverse_button",
+        "calc_natural_logarithm_button",
+        "calc_eulers_number_button",
+        "calc_abs_button",
+        "calc_factorial_button",
+        "calc_integer_portion_button",
+        "calc_exponential_button",
+        "calc_fractional_portion_button",
+        "calc_imaginary_button",
+        "subscript_togglebutton",
+        "superscript_togglebutton",
+        "calc_ans_button",
+        "calc_4_button",
+        "calc_7_button",
+        "calc_8_button",
+        "calc_9_button",
+        "calc_5_button",
+        "calc_6_button",
+        "calc_divide_button",
+        "calc_1_button",
+        "calc_2_button",
+        "calc_0_button",
+        "calc_numeric_point_button",
+        "calc_result_button",
+        "calc_3_button",
+        "calc_multiply_button",
+        "calc_subtract_button",
+        "calc_add_button",
+        "calc_clear_button",
+        "calc_start_group_button",
+        "calc_end_group_button",
+        "calc_percentage_button",
+        "calc_d_button",
+        "calc_e_button",
+        "calc_f_button",
+        "calc_a_button",
+        "calc_b_button",
+        "calc_c_button",
+        "calc_and_button",
+        "calc_or_button",
+        "calc_not_button",
+        "calc_xor_button",
+        "calc_xnor_button",
+        "calc_ones_complement_button",
+        "calc_twos_complement_button",
+        "calc_shift_right_button",
+        "calc_shift_left_button",
+        "calc_trunc_button",
+        "calc_random_button",
+        "calc_base_2_button",
+        "calc_base_8_button",
+        "calc_base_16_button",
+        "calc_si_kilo_button",
+        "calc_si_milli_button",
+        "calc_si_micro_button",
+        "calc_si_mega_button",
+        "calc_si_giga_button",
+        "calc_si_peta_button",
+        "calc_si_femto_button",
+        "calc_si_pico_button",
+        "calc_si_nano_button",
+        "calc_tangent_button",
+        "calc_sine_button",
+        "calc_cosine_button",
+        "calc_hyperbolic_cosine_button",
+        "calc_hyperbolic_sine_button",
+        "calc_hyperbolic_tangent_button",
+        NULL};
+
+    size_group = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
+    gtk_size_group_set_ignore_hidden(size_group, TRUE);
+    for (i = 0; button_names[i] != NULL; i++)
+        gtk_size_group_add_widget(size_group, GET_WIDGET(button_names[i]));
+}
+
+
 void
 ui_start(void)
 {
@@ -1897,5 +1999,13 @@ ui_start(void)
     
     gtk_widget_show(X.main_window);
 
+    /* Add buttons to size group so they are all the same size.
+     * 
+     * This is supported in GtkBuilder but it does not appear to work, setting
+     * the group after showing the widgets works. It would have been preferrable
+     * to make the table homogeneous but this does not ignore hidden rows.
+     */
+    add_buttons_to_size_group();
+
     gtk_main();
 }
diff --git a/src/unittest.c b/src/unittest.c
index dd4cf5d..6bcd123 100644
--- a/src/unittest.c
+++ b/src/unittest.c
@@ -109,10 +109,38 @@ test_parser()
     test("1½", "1.5", 0);    
     test("1.00", "1", 0);
     test("1.01", "1.01", 0);
+    //test("2A", "2000000000000000", 0);
+    test("2T", "2000000000000", 0);
+    test("2G", "2000000000", 0);
+    test("2M", "2000000", 0);
+    test("2k", "2000", 0);
+    test("2c", "0.02", 0);
+    test("2d", "0.2", 0);
+    test("2c", "0.02", 0);
+    test("2m", "0.002", 0);
+    test("2u", "0.000002", 0);
+    test("2µ", "0.000002", 0);
+    test("2n", "0.000000002", 0);
+    //test("2p", "0.000000000002", 0); // FIXME: Need to print out significant figures, not decimal places
+    //test("2f", "0.000000000000002", 0); // FIXME: Need to print out significant figures, not decimal places
+    //test("2A3", "2300000000000000", 0);
+    test("2T3", "2300000000000", 0);
+    test("2G3", "2300000000", 0);
+    test("2M3", "2300000", 0);
+    test("2k3", "2300", 0);
+    test("2c3", "0.023", 0);
+    test("2d3", "0.23", 0);
+    test("2c3", "0.023", 0);
+    test("2m3", "0.0023", 0);
+    test("2u3", "0.0000023", 0);
+    test("2µ3", "0.0000023", 0);
+    //test("2n3", "0.0000000023", 0); // FIXME: Need to print out significant figures, not decimal places
+    //test("2p3", "0.0000000000023", 0); // FIXME: Need to print out significant figures, not decimal places
+    //test("2f3", "0.0000000000000023", 0); // FIXME: Need to print out significant figures, not decimal places
     test("Ï?", "3.141592654", 0);
     test("2Ï?", "6.283185307", 0);
     test("e", "2.718281828", 0);
-    test("2e", "5.436563657", 0);    
+    test("2e", "5.436563657", 0);
 
     test("0+0", "0", 0);
     test("1+1", "2", 0);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]