[gcalctool] Make additional function popup in scientific mode



commit c5c27380c0ad869c0d2acc56d241137dfcce08f1
Author: Robert Ancell <robert ancell gmail com>
Date:   Mon Jun 7 11:20:07 2010 +1000

    Make additional function popup in scientific mode

 NEWS                     |    3 ++
 data/buttons-advanced.ui |   75 ++++++++++++++++++++++++++++++---------------
 src/math-buttons.c       |   54 ++++++++++++++++++++++++++++++++-
 3 files changed, 105 insertions(+), 27 deletions(-)
---
diff --git a/NEWS b/NEWS
index 2355f8d..3df661e 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,9 @@ Overview of changes in gcalctool 5.31.2
 
     * Support complex trigonometry
 
+    * Add complex argument button to scientific mode, make popup for additional
+      functions
+
 Overview of changes in gcalctool 5.31.2
 
     * Replace backspace button with undo button
diff --git a/data/buttons-advanced.ui b/data/buttons-advanced.ui
index b0d7777..ab7a4f1 100644
--- a/data/buttons-advanced.ui
+++ b/data/buttons-advanced.ui
@@ -127,8 +127,8 @@
               </packing>
             </child>
             <child>
-              <object class="GtkButton" id="calc_fractional_portion_button">
-                <property name="label">frac</property>
+              <object class="GtkButton" id="calc_imaginary_portion_button">
+                <property name="label">Im</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
@@ -633,7 +633,6 @@
                 <child>
                   <object class="GtkHBox" id="hbox19">
                     <property name="visible">True</property>
-                    <property name="spacing">3</property>
                     <child>
                       <object class="GtkLabel" id="label22">
                         <property name="visible">True</property>
@@ -680,7 +679,6 @@
                 <child>
                   <object class="GtkHBox" id="hbox20">
                     <property name="visible">True</property>
-                    <property name="spacing">3</property>
                     <child>
                       <object class="GtkLabel" id="label23">
                         <property name="visible">True</property>
@@ -743,8 +741,8 @@
               </packing>
             </child>
             <child>
-              <object class="GtkButton" id="calc_integer_portion_button">
-                <property name="label">int</property>
+              <object class="GtkButton" id="calc_real_portion_button">
+                <property name="label">Re</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
@@ -781,25 +779,6 @@
               </packing>
             </child>
             <child>
-              <object class="GtkButton" id="calc_imaginary_portion_button">
-                <property name="label">&#x2111;</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_underline">True</property>
-                <property name="focus_on_click">False</property>
-                <signal name="clicked" handler="button_cb"/>
-              </object>
-              <packing>
-                <property name="left_attach">9</property>
-                <property name="right_attach">10</property>
-                <property name="top_attach">4</property>
-                <property name="bottom_attach">5</property>
-                <property name="x_options">GTK_EXPAND | GTK_SHRINK | GTK_FILL</property>
-                <property name="y_options">GTK_EXPAND | GTK_SHRINK | GTK_FILL</property>
-              </packing>
-            </child>
-            <child>
               <object class="GtkButton" id="calc_arg_button">
                 <property name="label">Arg</property>
                 <property name="visible">True</property>
@@ -1081,6 +1060,52 @@
                 <property name="bottom_attach">2</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkButton" id="calc_function_button">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="focus_on_click">False</property>
+                <child internal-child="accessible">
+                  <object class="AtkObject" id="calc_function_button-atkobject">
+                    <property name="AtkObject::accessible-name" translatable="yes" comments="Accessible name for the store value button">Store</property>
+                  </object>
+                </child>
+                <signal name="clicked" handler="function_cb"/>
+                <child>
+                  <object class="GtkHBox" id="hbox2">
+                    <property name="visible">True</property>
+                    <child>
+                      <object class="GtkLabel" id="label5">
+                        <property name="visible">True</property>
+                        <property name="label">f(x)</property>
+                      </object>
+                      <packing>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkArrow" id="arrow1">
+                        <property name="visible">True</property>
+                        <property name="arrow_type">down</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">9</property>
+                <property name="right_attach">10</property>
+                <property name="top_attach">4</property>
+                <property name="bottom_attach">5</property>
+                <property name="x_options">GTK_EXPAND | GTK_SHRINK | GTK_FILL</property>
+                <property name="y_options">GTK_EXPAND | GTK_SHRINK | GTK_FILL</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="position">1</property>
diff --git a/src/math-buttons.c b/src/math-buttons.c
index 60bec85..7df1288 100644
--- a/src/math-buttons.c
+++ b/src/math-buttons.c
@@ -48,6 +48,8 @@ struct MathButtonsPrivate
 
     GtkWidget *shift_left_menu, *shift_right_menu;
 
+    GtkWidget *function_menu;
+
     GList *superscript_toggles;
     GList *subscript_toggles;
 
@@ -127,6 +129,9 @@ static ButtonData button_data[] = {
     {"modulus_divide",     " mod ", OPERATOR,
       /* Tooltip for the modulus divide button */
       N_("Modulus divide")},
+    {"function",           NULL, FUNCTION,
+      /* Tooltip for the additional functions button */
+      N_("Additional Functions")},
     {"x_pow_y",            "^", FUNCTION,
       /* Tooltip for the exponent button */
       N_("Exponent [^ or **]")},
@@ -199,10 +204,10 @@ static ButtonData button_data[] = {
     {"fractional_portion", "frac ", FUNCTION,
       /* Tooltip for the fractional component button */
       N_("Fractional Component")},
-    {"real_portion",       "re ", FUNCTION,
+    {"real_portion",       "Re ", FUNCTION,
       /* Tooltip for the real component button */
       N_("Real Component")},
-    {"imaginary_portion",  "im ", FUNCTION,
+    {"imaginary_portion",  "Im ", FUNCTION,
       /* Tooltip for the imaginary component button */
       N_("Imaginary Component")},
     {"ones_complement",    "ones ", FUNCTION,
@@ -1255,6 +1260,51 @@ shift_right_cb(GtkWidget *widget, MathButtons *buttons)
 }
 
 
+static void
+insert_function_cb(GtkWidget *widget, MathButtons *buttons)
+{
+    math_equation_insert(buttons->priv->equation, g_object_get_data(G_OBJECT(widget), "function"));
+}
+
+
+G_MODULE_EXPORT
+void
+function_cb(GtkWidget *widget, MathButtons *buttons)
+{
+    if (!buttons->priv->function_menu) {
+        gint i;
+        GtkWidget *menu;
+        struct 
+        {
+            gchar *name, *function;
+        } functions[] = 
+        {
+            { /* Tooltip for the integer component button */
+              N_("Integer Component"), "int " },
+            { /* Tooltip for the fractional component button */
+              N_("Fractional Component"), "frac " },
+            { NULL, NULL }
+        };
+
+        menu = buttons->priv->function_menu = gtk_menu_new();
+        gtk_menu_set_reserve_toggle_size(GTK_MENU(menu), FALSE);
+        set_tint(menu, &buttons->priv->color_function, 1);
+
+        for (i = 0; functions[i].name != NULL; i++) {
+            GtkWidget *item;
+          
+            item = gtk_menu_item_new_with_label(_(functions[i].name));
+            g_object_set_data(G_OBJECT(item), "function", g_strdup (functions[i].function));
+            gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+            g_signal_connect(item, "activate", G_CALLBACK(insert_function_cb), buttons);
+            gtk_widget_show(item);
+        }
+    }
+
+    popup_button_menu(widget, GTK_MENU(buttons->priv->function_menu));  
+}
+
+
 G_MODULE_EXPORT
 void
 factorize_cb(GtkWidget *widget, MathButtons *buttons)



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