r22274 - gnucash/trunk/src - Remove depreciated Option functions - part 1

Geert Janssens gjanssens at code.gnucash.org
Wed Aug 1 09:53:58 EDT 2012


Author: gjanssens
Date: 2012-08-01 09:53:58 -0400 (Wed, 01 Aug 2012)
New Revision: 22274
Trac: http://svn.gnucash.org/trac/changeset/22274

Added:
   gnucash/trunk/src/gnome-utils/gnc-combott.c
   gnucash/trunk/src/gnome-utils/gnc-combott.h
Modified:
   gnucash/trunk/src/gnome-utils/Makefile.am
   gnucash/trunk/src/gnome-utils/dialog-options.c
   gnucash/trunk/src/gnome-utils/dialog-options.h
   gnucash/trunk/src/gnome-utils/dialog-utils.c
   gnucash/trunk/src/gnome-utils/dialog-utils.h
   gnucash/trunk/src/import-export/import-format-dialog.c
Log:
Remove depreciated Option functions - part 1

The option menu's that appear in dialog options rely on per item tool
tips that GtkComboBox did not have. From a comment in the code, this was
highlighted on bug http://bugzilla.gnome.org/show_bug.cgi?id=303717
which implies this is now fixed but I could not see a way of adding them
so I created my own basic combo with per item tooltips.

This basic combo uses an external list store to reduce the functions
needed and can be seen when changing report settings. It look like it
does the job OK but may be I have missed something. 

I have added comments in the code in areas that would need to be changed
if GtkComboBox ever has per item tool tips.

Patch by Robert Fewell

Modified: gnucash/trunk/src/gnome-utils/Makefile.am
===================================================================
--- gnucash/trunk/src/gnome-utils/Makefile.am	2012-07-27 15:49:51 UTC (rev 22273)
+++ gnucash/trunk/src/gnome-utils/Makefile.am	2012-08-01 13:53:58 UTC (rev 22274)
@@ -49,6 +49,7 @@
   gnc-account-sel.c \
   gnc-amount-edit.c \
   gnc-autosave.c \
+  gnc-combott.c \
   gnc-commodity-edit.c \
   gnc-currency-edit.c \
   gnc-date-delta.c \
@@ -122,6 +123,7 @@
   dialog-utils.h \
   gnc-account-sel.h \
   gnc-amount-edit.h \
+  gnc-combott.h \
   gnc-commodity-edit.h \
   gnc-currency-edit.h \
   gnc-date-delta.h \

Modified: gnucash/trunk/src/gnome-utils/dialog-options.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-options.c	2012-07-27 15:49:51 UTC (rev 22273)
+++ gnucash/trunk/src/gnome-utils/dialog-options.c	2012-08-01 13:53:58 UTC (rev 22274)
@@ -38,6 +38,7 @@
 #include "glib-helpers.h"
 #include "gnc-account-sel.h"
 #include "gnc-tree-view-account.h"
+#include "gnc-combott.h"
 #include "gnc-commodity-edit.h"
 #include "gnc-component-manager.h"
 #include "gnc-general-select.h"
@@ -414,63 +415,14 @@
     gnc_option_changed_widget_cb(widget, option);
 }
 
-#ifdef GTKCOMBOBOX_TOOLTIPS_WORK
 static void
 gnc_option_multichoice_cb(GtkWidget *widget, gpointer data)
 {
     GNCOption *option = data;
+    /* GtkComboBox per-item tooltip changes needed below */
     gnc_option_changed_widget_cb(widget, option);
 }
-#else
-static void
-gnc_option_multichoice_cb(GtkWidget *w, gint index, gpointer data)
-{
-    GNCOption *option = data;
-    GtkWidget *widget;
-    GtkWidget *omenu;
-    gpointer _current;
-    gint current;
-    char *type;
 
-    widget = gnc_option_get_gtk_widget (option);
-
-    /* the option menu may be part of a date option widget, so we need to
-       decomposit the enclosing hbox then */
-    type = gnc_option_type (option);
-    if (safe_strcmp (type, "date") == 0)
-    {
-        char *date_type = gnc_option_date_option_get_subtype(option);
-        GList *children;
-
-        if (safe_strcmp (date_type, "both") == 0)
-        {
-            children = gtk_container_get_children (GTK_CONTAINER (widget));
-            widget = g_list_nth_data (children, GNC_RD_WID_REL_WIDGET_POS);
-            g_list_free(children);
-        }
-        free (date_type);
-    }
-    free (type);
-
-    _current = g_object_get_data(G_OBJECT(widget), "gnc_multichoice_index");
-    current = GPOINTER_TO_INT(_current);
-
-    if (current == index)
-        return;
-
-    gtk_option_menu_set_history(GTK_OPTION_MENU(widget), index);
-    g_object_set_data(G_OBJECT(widget), "gnc_multichoice_index",
-                      GINT_TO_POINTER(index));
-
-    gnc_option_set_changed (option, TRUE);
-
-    gnc_option_call_option_widget_changed_proc(option);
-
-    omenu = g_object_get_data(G_OBJECT(w), "gnc_option_menu");
-    gnc_options_dialog_changed_internal (omenu, TRUE);
-}
-#endif
-
 static void
 gnc_option_radiobutton_cb(GtkWidget *w, gpointer data)
 {
@@ -531,69 +483,39 @@
 
         g_return_val_if_fail(num_values >= 0, NULL);
 
-#ifdef GTKCOMBOBOX_TOOLTIPS_WORK
         {
-            /* New code for GtkComboBox. Is not used because it is missing
-             * the feature of per-item tooltips. Not yet implemented in gtk,
-             * see http://bugzilla.gnome.org/show_bug.cgi?id=303717 , see
-             * also gnc_option_create_multichoice_widget() below. */
-            char *string;
-            rel_widget = gtk_combo_box_text_new();
+        /* GtkComboBox still does not support per-item tooltips, so have
+           created a basic one called Combott implemented in gnc-combott.
+           Have highlighted changes in this file with comments for when  
+           the feature of per-item tooltips is implemented in gtk,
+           see http://bugzilla.gnome.org/show_bug.cgi?id=303717 */
+
+            GtkListStore *store;
+            GtkTreeIter  iter;
+
+            char *itemstring;
+            char *description;
+            store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
+            /* Add values to the list store, entry and tooltip */
             for (i = 0; i < num_values; i++)
             {
-                string = gnc_option_permissible_value_name(option, i);
-                gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(rel_widget), string);
-                g_free(string);
+                itemstring = gnc_option_permissible_value_name(option, i);
+                description = gnc_option_permissible_value_description(option, i);
+                gtk_list_store_append (store, &iter);
+                gtk_list_store_set (store, &iter, 0, itemstring, 1, description, -1);
+                if (itemstring)
+                    g_free(itemstring);
+                if (description)
+                    g_free(description);
             }
+            /* Create the new Combo with tooltip and add the store */
+            rel_widget = GTK_WIDGET(gnc_combott_new());
+            g_object_set( G_OBJECT(rel_widget), "model", GTK_TREE_MODEL(store), NULL );
+            g_object_unref(store);
 
             g_signal_connect(G_OBJECT(rel_widget), "changed",
                              G_CALLBACK(gnc_option_multichoice_cb), option);
         }
-#else
-        {
-            /* Old 1-8-branch code for a GtkOptionMenu. We use this one
-             * because it has a per-item tooltip which the GtkComboBox still
-             * doesn't have. - cstim, 2006-02-25 */
-            GNCOptionInfo *info;
-            char **raw_strings;
-            char **raw;
-
-            info = g_new0(GNCOptionInfo, num_values);
-            raw_strings = g_new0(char *, num_values * 2);
-            raw = raw_strings;
-
-            for (i = 0; i < num_values; i++)
-            {
-                *raw = gnc_option_permissible_value_name(option, i);
-                info[i].name = *raw; /* (*raw && **raw) ? _(*raw) : ""; */
-
-                raw++;
-
-                *raw = gnc_option_permissible_value_description(option, i);
-                info[i].tip = *raw; /* (*raw && **raw) ? _(*raw) : ""; */
-
-                if (safe_strcmp(type, "both") == 0)
-                {
-                    info[i].callback = gnc_option_multichoice_cb; /* gnc_option_rd_combo_cb */
-                }
-                else
-                {
-                    info[i].callback = gnc_option_multichoice_cb;
-                }
-                info[i].user_data = option;
-                raw++;
-            }
-
-            rel_widget = gnc_build_option_menu(info, num_values);
-
-            for (i = 0; i < num_values * 2; i++)
-                if (raw_strings[i])
-                    free(raw_strings[i]);
-
-            g_free(raw_strings);
-            g_free(info);
-        }
-#endif
     }
 
     if (safe_strcmp(type, "absolute") == 0)
@@ -667,69 +589,38 @@
 
     g_return_val_if_fail(num_values >= 0, NULL);
 
-#ifndef GTKCOMBOBOX_TOOLTIPS_WORK
     {
-        /* Old 1-8-branch code for a GtkOptionMenu. We use this one
-           because it has a per-item tooltip which the GtkComboBox still
-           doesn't have. - cstim, 2006-02-25 */
-        GNCOptionInfo *info;
-        char **raw_strings;
-        char **raw;
-
-        info = g_new0(GNCOptionInfo, num_values);
-        raw_strings = g_new0(char *, num_values * 2);
-        raw = raw_strings;
-
-        for (i = 0; i < num_values; i++)
-        {
-            *raw = gnc_option_permissible_value_name(option, i);
-            info[i].name = (*raw && **raw) ? _(*raw) : "";
-
-            raw++;
-
-            *raw = gnc_option_permissible_value_description(option, i);
-            info[i].tip = (*raw && **raw) ? _(*raw) : "";
-
-            info[i].callback = gnc_option_multichoice_cb;
-            info[i].user_data = option;
-            raw++;
-        }
-
-        widget = gnc_build_option_menu(info, num_values);
-
-        for (i = 0; i < num_values * 2; i++)
-            if (raw_strings[i])
-                free(raw_strings[i]);
-
-        g_free(raw_strings);
-        g_free(info);
-    }
-#else
-    {
-
-        /* New code for GtkComboBox. Is still unused because it is missing
-           the feature of per-item tooltips. Not yet implemented in gtk,
+        /* GtkComboBox still does not support per-item tooltips, so have
+           created a basic one called Combott implemented in gnc-combott.
+           Have highlighted changes in this file with comments for when  
+           the feature of per-item tooltips is implemented in gtk,
            see http://bugzilla.gnome.org/show_bug.cgi?id=303717 */
+        GtkListStore *store;
+        GtkTreeIter  iter;
+
         char *itemstring;
-        /* char *description; */
-        widget = gtk_combo_box_text_new();
+        char *description;
+        store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
+        /* Add values to the list store, entry and tooltip */
         for (i = 0; i < num_values; i++)
         {
             itemstring = gnc_option_permissible_value_name(option, i);
-            /* description = gnc_option_permissible_value_description(option, i); */
-            gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widget),
-                                      (itemstring && *itemstring) ? _(itemstring) : "");
-            /*, (description && *description) ? _(description) : "" */
-            /* Maybe the per-item tooltip will simply be added as such an
-            	 additional argument as shown above, but we'll see. */
+            description = gnc_option_permissible_value_description(option, i);
+            gtk_list_store_append (store, &iter);
+            gtk_list_store_set (store, &iter, 0, itemstring, 1, description, -1);
             if (itemstring)
                 g_free(itemstring);
-            /* if (description) g_free(description); */
+            if (description)
+                g_free(description);
         }
+        /* Create the new Combo with tooltip and add the store */
+        widget = GTK_WIDGET(gnc_combott_new());
+        g_object_set( G_OBJECT( widget ), "model", GTK_TREE_MODEL(store), NULL );
+        g_object_unref(store);
+
         g_signal_connect(G_OBJECT(widget), "changed",
                          G_CALLBACK(gnc_option_multichoice_cb), option);
     }
-#endif
 
     return widget;
 }
@@ -1050,7 +941,6 @@
     g_signal_connect(selection, "changed",
                      G_CALLBACK(gnc_option_list_changed_cb), option);
 
-
     bbox = gtk_vbutton_box_new();
     gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_SPREAD);
     gtk_box_pack_start(GTK_BOX(hbox), bbox, FALSE, FALSE, 10);
@@ -1932,7 +1822,9 @@
                      G_CALLBACK(gnc_option_changed_widget_cb), option);
 
     gnc_option_set_widget (option, value);
-    gnc_option_set_ui_value(option, FALSE);
+    /* DOCUMENT ME: Why is the only option type that sets use_default to
+       TRUE? */
+    gnc_option_set_ui_value(option, TRUE);
 
     *enclosing = gtk_hbox_new(FALSE, 5);
     gtk_box_pack_start(GTK_BOX(*enclosing), label, FALSE, FALSE, 0);
@@ -2345,13 +2237,8 @@
         return TRUE;
     else
     {
-#ifdef GTKCOMBOBOX_TOOLTIPS_WORK
-        gtk_combo_box_set_active(GTK_COMBO_BOX(widget), index);
-#else
-        gtk_option_menu_set_history(GTK_OPTION_MENU(widget), index);
-        g_object_set_data(G_OBJECT(widget), "gnc_multichoice_index",
-                          GINT_TO_POINTER(index));
-#endif
+        /* GtkComboBox per-item tooltip changes needed below */
+        gnc_combott_set_active(GNC_COMBOTT(widget), index);
         return FALSE;
     }
 }
@@ -2379,14 +2266,8 @@
                 index = gnc_option_permissible_value_index(option, relative);
                 if (safe_strcmp(date_option_type, "relative") == 0)
                 {
-#ifdef GTKCOMBOBOX_TOOLTIPS_WORK
-                    gtk_combo_box_set_active(GTK_COMBO_BOX(widget), index);
-#else
-                    g_object_set_data(G_OBJECT(widget),
-                                      "gnc_multichoice_index",
-                                      GINT_TO_POINTER(index));
-                    gtk_option_menu_set_history(GTK_OPTION_MENU(widget), index);
-#endif
+                    /* GtkComboBox per-item tooltip changes needed below */
+                    gnc_combott_set_active(GNC_COMBOTT(widget), index);
                 }
                 else if (safe_strcmp(date_option_type, "both") == 0)
                 {
@@ -2398,15 +2279,8 @@
                                                       GNC_RD_WID_REL_WIDGET_POS);
                     g_list_free(widget_list);
                     gnc_date_option_set_select_method(option, FALSE, TRUE);
-#ifdef GTKCOMBOBOX_TOOLTIPS_WORK
-                    gtk_combo_box_set_active(GTK_COMBO_BOX(rel_date_widget), index);
-#else
-                    g_object_set_data(G_OBJECT(rel_date_widget),
-                                      "gnc_multichoice_index",
-                                      GINT_TO_POINTER(index));
-                    gtk_option_menu_set_history(GTK_OPTION_MENU(rel_date_widget),
-                                                index);
-#endif
+                    /* GtkComboBox per-item tooltip changes needed below */
+                    gnc_combott_set_active(GNC_COMBOTT(rel_date_widget), index);
                 }
                 else
                 {
@@ -2802,14 +2676,8 @@
 {
     int index;
 
-#ifdef GTKCOMBOBOX_TOOLTIPS_WORK
-    index = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
-#else
-    {
-        gpointer _index = g_object_get_data(G_OBJECT(widget), "gnc_multichoice_index");
-        index = GPOINTER_TO_INT(_index);
-    }
-#endif
+    /* GtkComboBox per-item tooltip changes needed below */
+    index = gnc_combott_get_active(GNC_COMBOTT(widget));
     return (gnc_option_permissible_value(option, index));
 }
 
@@ -2822,12 +2690,9 @@
 
     if (safe_strcmp(subtype, "relative") == 0)
     {
-#ifdef GTKCOMBOBOX_TOOLTIPS_WORK
-        index = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
-#else
-        index = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget),
-                                "gnc_multichoice_index"));
-#endif
+        /* GtkComboBox per-item tooltip changes needed below */
+        index = gnc_combott_get_active(GNC_COMBOTT(widget));
+
         type = scm_str2symbol("relative");
         val = gnc_option_permissible_value(option, index);
         result = scm_cons(type, val);
@@ -2864,12 +2729,9 @@
         }
         else
         {
-#ifdef GTKCOMBOBOX_TOOLTIPS_WORK
-            index = gtk_combo_box_get_active(GTK_COMBO_BOX(rel_widget));
-#else
-            index = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(rel_widget),
-                                    "gnc_multichoice_index"));
-#endif
+            /* GtkComboBox per-item tooltip changes needed below */
+            index = gnc_combott_get_active(GNC_COMBOTT(rel_widget));
+
             val = gnc_option_permissible_value(option, index);
             result = scm_cons(scm_str2symbol("relative"), val);
         }

Modified: gnucash/trunk/src/gnome-utils/dialog-options.h
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-options.h	2012-07-27 15:49:51 UTC (rev 22273)
+++ gnucash/trunk/src/gnome-utils/dialog-options.h	2012-08-01 13:53:58 UTC (rev 22274)
@@ -45,6 +45,7 @@
 GtkWidget * gnc_options_dialog_notebook(GNCOptionWin * win);
 
 void gnc_options_dialog_changed (GNCOptionWin *win);
+
 void gnc_option_changed_widget_cb(GtkWidget *widget, GNCOption *option);
 void gnc_option_changed_option_cb(GtkWidget *dummy, GNCOption *option);
 

Modified: gnucash/trunk/src/gnome-utils/dialog-utils.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-utils.c	2012-07-27 15:49:51 UTC (rev 22273)
+++ gnucash/trunk/src/gnome-utils/dialog-utils.c	2012-08-01 13:53:58 UTC (rev 22274)
@@ -47,82 +47,7 @@
 #define WINDOW_POSITION		"window_position"
 #define WINDOW_GEOMETRY		"window_geometry"
 
-/* =========================================================== */
-
-static void
-gnc_option_menu_cb(GtkWidget *w, gpointer data)
-{
-    GNCOptionCallback cb;
-    gpointer _index;
-    gint index;
-
-    cb = g_object_get_data(G_OBJECT(w), "gnc_option_cb");
-
-#ifdef GTKCOMBOBOX_TOOLTIPS_WORK
-    cb(w, data);
-#else
-    _index = g_object_get_data(G_OBJECT(w), "gnc_option_index");
-    index = GPOINTER_TO_INT(_index);
-
-    cb(w, index, data);
-#endif
-}
-
 /********************************************************************\
- * gnc_build_option_menu:                                           *
- *   create an GTK "option menu" given the option structure         *
- *                                                                  *
- * Args: option_info - the option structure to use                  *
- *       num_options - the number of options                        *
- * Returns: void                                                    *
- \*******************************************************************/
-GtkWidget *
-gnc_build_option_menu(GNCOptionInfo *option_info, gint num_options)
-{
-    GtkWidget *omenu;
-    GtkWidget *menu;
-    GtkWidget *menu_item;
-    gint i;
-
-    omenu = gtk_option_menu_new();
-    gtk_widget_show(omenu);
-
-    menu = gtk_menu_new();
-    gtk_widget_show(menu);
-
-    for (i = 0; i < num_options; i++)
-    {
-        menu_item = gtk_menu_item_new_with_label(option_info[i].name);
-        gtk_widget_set_tooltip_text(menu_item, option_info[i].tip);
-        gtk_widget_show(menu_item);
-
-        g_object_set_data(G_OBJECT(menu_item),
-                          "gnc_option_cb",
-                          option_info[i].callback);
-
-        g_object_set_data(G_OBJECT(menu_item),
-                          "gnc_option_index",
-                          GINT_TO_POINTER(i));
-
-        g_object_set_data(G_OBJECT(menu_item),
-                          "gnc_option_menu",
-                          omenu);
-
-        if (option_info[i].callback != NULL)
-            g_signal_connect(menu_item, "activate",
-                             G_CALLBACK(gnc_option_menu_cb),
-                             option_info[i].user_data);
-
-        gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
-    }
-
-    gtk_option_menu_set_menu(GTK_OPTION_MENU(omenu), menu);
-
-    return omenu;
-}
-
-
-/********************************************************************\
  * gnc_get_toolbar_style                                            *
  *   returns the current toolbar style for gnucash toolbars         *
  *                                                                  *
@@ -154,6 +79,7 @@
     return tbstyle;
 }
 
+
 /********************************************************************\
  * gnc_get_deficit_color                                            *
  *   fill in the 3 color values for the color of deficit values     *

Modified: gnucash/trunk/src/gnome-utils/dialog-utils.h
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-utils.h	2012-07-27 15:49:51 UTC (rev 22273)
+++ gnucash/trunk/src/gnome-utils/dialog-utils.h	2012-08-01 13:53:58 UTC (rev 22274)
@@ -29,32 +29,6 @@
 #include <gtk/gtk.h>
 #include "qof.h"
 
-/* option button callback function */
-#ifdef GTKCOMBOBOX_TOOLTIPS_WORK
-typedef void (*GNCOptionCallback) (GtkWidget *,
-                                   gpointer user_data);
-#else
-typedef void (*GNCOptionCallback) (GtkWidget *, gint index,
-                                   gpointer user_data);
-#endif
-
-/* Structure for building option buttons */
-typedef struct _GNCOptionInfo GNCOptionInfo;
-struct _GNCOptionInfo
-{
-    char *name;
-    char *tip;
-    GNCOptionCallback callback;
-    gpointer user_data;
-};
-
-
-/**** PROTOTYPES *************************************************/
-
-GtkWidget * gnc_build_option_menu (GNCOptionInfo *option_info,
-                                   gint num_options);
-
-
 GtkToolbarStyle gnc_get_toolbar_style (void);
 void gnc_get_deficit_color (GdkColor *color);
 void gnc_set_label_color (GtkWidget *label, gnc_numeric value);

Added: gnucash/trunk/src/gnome-utils/gnc-combott.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-combott.c	                        (rev 0)
+++ gnucash/trunk/src/gnome-utils/gnc-combott.c	2012-08-01 13:53:58 UTC (rev 22274)
@@ -0,0 +1,707 @@
+/********************************************************************\
+ * gnc-combott.c -- Basic simulation of ComboBox with tooltips for  *
+ *                  each item.                                      *
+ * Copyright (c) 2012 Robert Fewell                                 *
+ *                                                                  *
+ *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
+ * This widget requires external ListStore which has two columns.   *
+ * By default, column 0 holds the text to display and column 1 the  *
+ * per item tooltip but these can be specified if the liststore has *
+ * a different format.                                              *
+ *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+\********************************************************************/
+#include <gtk/gtk.h>
+#include "gnc-combott.h"
+#include <strings.h>
+#include <string.h>
+
+enum {
+  CHANGED,
+  LAST_SIGNAL
+};
+
+enum {
+	PROP_0,
+        PROP_MODEL,
+        PROP_ACTIVE,
+        PROP_TEXT_COL,
+        PROP_TIP_COL,
+};
+
+#define GNC_COMBOTT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_COMBOTT, GncCombottPrivate))
+
+static guint combott_signals[LAST_SIGNAL] = {0,};
+
+typedef struct GncCombottPrivate
+{
+    GtkTreeModel  *model;
+    GtkWidget     *button;
+    GtkWidget     *label;
+    GtkWidget     *menu;
+    GtkTreeIter    active_iter;
+    gint           active;
+
+    gint	   text_col;
+    gint	   tip_col;
+
+    gint           max_number_char;
+    gint           num_items;
+
+    gint           x;
+    gint           y;
+    gint           width;
+    gint           height;
+
+}GncCombottPrivate;
+
+/** Declarations *********************************************************/
+static void gctt_init (GncCombott *combott);
+
+static void gctt_class_init (GncCombottClass *class);
+
+static void gctt_set_property (GObject *object,
+			       guint param_id,
+			       const GValue *value,
+			       GParamSpec *pspec);
+
+static void gctt_get_property (GObject *object,
+			       guint param_id,
+			       GValue *value,
+			       GParamSpec *pspec);
+
+static void gctt_finalize (GObject *object);
+
+static void gctt_combott_menu_position (GtkMenu *menu,
+                                        gint *x,
+                                        gint *y,
+                                        gint *push_in,
+                                        gpointer user_data);
+
+static void gctt_changed (GncCombott *combott);
+static void gctt_set_model (GncCombott *combott, GtkTreeModel *model);
+static void gctt_refresh_menu (GncCombott *combott, GtkTreeModel *model);
+static void gctt_rebuild_menu (GncCombott *combott, GtkTreeModel *model);
+
+static gboolean which_tooltip_cb (GtkWidget  *widget, gint x, gint y,
+				 gboolean keyboard_mode, GtkTooltip *tooltip, gpointer user_data);
+static gboolean button_press_cb (GtkWidget *widget, GdkEvent *event, gpointer *user_data );
+static void button_getsize_cb (GtkWidget *widget, GtkAllocation *allocation, gpointer *user_data);
+static void menu_getsize_cb (GtkWidget *widget, GtkAllocation *allocation, gpointer *user_data);
+static void menuitem_response_cb (GtkMenuItem *item, gpointer *user_data);
+
+
+/************************************************************/
+/*               g_object required functions                */
+/************************************************************/
+static GObjectClass *parent_class = NULL;
+
+GType
+gnc_combott_get_type (void)
+{
+    static GType combott_type = 0;
+
+    if (!combott_type) {
+	static const GTypeInfo combott_info = {
+		sizeof (GncCombottClass),
+		NULL,		/* base_init */
+		NULL,		/* base_finalize */
+		(GClassInitFunc) gctt_class_init,
+		NULL,		/* class_finalize */
+		NULL,		/* class_data */
+		sizeof (GncCombott),
+		0,              /* n_preallocs */
+		(GInstanceInitFunc) gctt_init,
+	};
+
+	combott_type = g_type_register_static (GTK_TYPE_HBOX,
+						 "GncCombott",
+						 &combott_info, 0);
+    }
+    return combott_type;
+}
+
+
+static void
+gctt_class_init (GncCombottClass *class)
+{
+    GObjectClass            *gobject_class;
+
+    parent_class = g_type_class_peek_parent (class);
+    gobject_class = G_OBJECT_CLASS (class);
+
+    gobject_class->set_property = gctt_set_property;
+    gobject_class->get_property = gctt_get_property;
+    gobject_class->finalize = gctt_finalize;
+
+    class->changed = gctt_changed;
+
+    combott_signals[CHANGED] =
+    g_signal_new ("changed",
+                  G_OBJECT_CLASS_TYPE (class),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (GncCombottClass, changed),
+                  NULL, NULL,
+                  g_cclosure_marshal_VOID__VOID,
+                  G_TYPE_NONE, 0);
+
+    g_object_class_install_property (
+	 	 gobject_class,
+                 PROP_MODEL,
+                 g_param_spec_object ("model",
+				       "Combott model",
+				       "The model for the combo tooltip",
+				       GTK_TYPE_TREE_MODEL,
+				       G_PARAM_READWRITE));
+
+    g_object_class_install_property (
+	 	 gobject_class,
+                 PROP_TEXT_COL,
+                 g_param_spec_int ("text-col",
+				       "text column",
+				       "Column for the text",
+                                       0,
+                                       G_MAXINT,
+                                       0,
+                                       G_PARAM_READWRITE));
+
+    g_object_class_install_property (
+	 	 gobject_class,
+                 PROP_TIP_COL,
+                 g_param_spec_int ("tip-col",
+				       "tip column",
+				       "Column for the tip",
+                                       0,
+                                       G_MAXINT,
+                                       1,
+                                       G_PARAM_READWRITE));
+
+    g_type_class_add_private(class, sizeof(GncCombottPrivate));
+}
+
+
+static void
+gctt_init (GncCombott *combott)
+{
+    GtkWidget *hbox;
+    GtkWidget *label;
+    GtkWidget *arrow;
+    GtkWidget *button;
+    GtkWidget *sep;
+
+    GncCombottPrivate *priv = GNC_COMBOTT_GET_PRIVATE (combott);
+
+    priv->active = 0;
+    priv->text_col = 0;
+    priv->tip_col = 1;
+
+    hbox = gtk_hbox_new(FALSE, 0);
+
+    arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
+    gtk_box_pack_end (GTK_BOX (hbox), arrow, FALSE, FALSE, 0);
+
+    sep = gtk_vseparator_new();
+    gtk_box_pack_end (GTK_BOX (hbox), sep, FALSE, FALSE, 0);
+
+    label = gtk_label_new(NULL);
+    gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+    priv->label = label;
+
+    button = gtk_button_new();
+    gtk_container_add(GTK_CONTAINER(button), GTK_WIDGET(hbox));
+    priv->button = button;
+
+    gtk_container_add(GTK_CONTAINER(combott), GTK_WIDGET(button));
+
+    g_signal_connect (button, "event",
+	                 G_CALLBACK (button_press_cb), combott);
+
+    gtk_widget_set_has_tooltip (GTK_WIDGET(combott), TRUE);
+
+    g_signal_connect(G_OBJECT(combott), "query-tooltip",
+                         G_CALLBACK(which_tooltip_cb), combott);
+
+    g_signal_connect(G_OBJECT(combott), "size-allocate",
+			 G_CALLBACK(button_getsize_cb), combott);
+
+    gtk_widget_show(GTK_WIDGET(priv->button));
+}
+
+
+static void
+gctt_set_property (GObject      *object,
+		   guint         param_id,
+		   const GValue *value,
+		   GParamSpec   *pspec)
+{
+    GncCombott *combott = GNC_COMBOTT (object);
+    GncCombottPrivate *priv = GNC_COMBOTT_GET_PRIVATE (combott);
+	
+    switch (param_id) {
+    case PROP_MODEL:
+         gctt_set_model (combott, g_value_get_object (value));
+	 break;
+
+    case PROP_ACTIVE:
+         gnc_combott_set_active (combott, g_value_get_int (value));
+         break;
+
+    case PROP_TEXT_COL:
+         priv->text_col = g_value_get_int (value);
+         break;
+
+    case PROP_TIP_COL:
+         priv->tip_col = g_value_get_int (value);
+         gctt_refresh_menu(combott, priv->model);
+         break;
+
+    default:
+	 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+	 break;
+    }
+}
+
+
+static void
+gctt_get_property (GObject    *object,
+		   guint       param_id,
+		   GValue     *value,
+		   GParamSpec *pspec)
+{
+    GncCombott *combott = GNC_COMBOTT (object);
+    GncCombottPrivate *priv = GNC_COMBOTT_GET_PRIVATE (combott);
+	
+    switch (param_id) {
+    case PROP_MODEL:
+	 g_value_set_object (value, priv->model);
+	 break;
+
+    case PROP_ACTIVE:
+         g_value_set_int (value, gnc_combott_get_active (combott));
+         break;
+
+    case PROP_TEXT_COL:
+         g_value_set_int (value, priv->text_col);
+         break;
+
+    case PROP_TIP_COL:
+         g_value_set_int (value, priv->tip_col);
+         break;
+
+    default:
+	 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+	 break;
+    }
+}
+
+
+static void
+gctt_finalize (GObject *object)
+{
+    GncCombott *combott;
+    GncCombottPrivate *priv;
+
+    g_return_if_fail (object != NULL);
+    g_return_if_fail (GNC_IS_COMBOTT (object));
+
+    combott = GNC_COMBOTT (object);
+    priv = GNC_COMBOTT_GET_PRIVATE (combott);
+
+    if (priv->model)
+    {
+        priv->model = NULL;
+    }
+
+    if (priv->menu)
+    {
+        priv->menu = NULL;
+    }
+
+    G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+
+static void
+gctt_set_model (GncCombott *combott, GtkTreeModel *model)
+{
+    GncCombottPrivate *priv;
+
+    g_return_if_fail (GNC_IS_COMBOTT (combott));
+    g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
+
+    priv = GNC_COMBOTT_GET_PRIVATE (combott);
+
+    gctt_rebuild_menu(combott, model);
+
+    priv->model = model;
+    g_object_ref (priv->model);
+}
+
+
+static void
+gctt_rebuild_menu (GncCombott *combott, GtkTreeModel *model)
+{
+    GncCombottPrivate *priv;
+    GtkTreeIter iter;
+    GtkWidget *menu_items;
+    gboolean valid;
+    gint num = 1;
+    gint items = 0;
+
+    g_return_if_fail (GNC_IS_COMBOTT (combott));
+    g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
+
+    priv = GNC_COMBOTT_GET_PRIVATE (combott);
+
+    priv->menu = NULL;
+
+    priv->menu = gtk_menu_new();
+
+    valid = gtk_tree_model_get_iter_first (model, &iter);
+    while (valid)
+    {
+        GtkWidget *label;
+
+        /* Walk through the list, reading each row */
+        gchar *str_data;
+        gchar *tip_data;
+        gtk_tree_model_get (model, &iter,
+                          priv->text_col, &str_data,
+                          priv->tip_col, &tip_data,
+                         -1);
+
+        /* Create a new menu-item with a name... */
+        menu_items = gtk_menu_item_new_with_label (str_data);
+
+        /* Get widget width to max number of characters in list */
+        if(strlen(str_data) > num)
+            num = strlen(str_data);
+
+        /* Add the tooltip to the child label */
+        label = gtk_bin_get_child(GTK_BIN(menu_items));
+        gtk_widget_set_tooltip_text (label, tip_data);
+        gtk_misc_set_alignment (GTK_MISC(label), 0, 0.5);
+
+        /* ...and add it to the menu. */
+        gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_items);
+        g_signal_connect (menu_items, "activate",
+		                      G_CALLBACK (menuitem_response_cb),
+                                      combott);
+
+        /* Show the widget */
+        gtk_widget_show (menu_items);
+
+        g_free (str_data);
+        g_free (tip_data);
+        items++;
+        valid = gtk_tree_model_iter_next (model, &iter);
+        }
+
+    g_signal_connect(G_OBJECT(priv->menu), "size-allocate", G_CALLBACK(menu_getsize_cb), combott);
+
+    /* Set widget width to max number of characters in list */
+    priv->max_number_char = num;
+    gtk_label_set_width_chars(GTK_LABEL(priv->label), priv->max_number_char);
+
+    priv->num_items = items;
+}
+
+
+static void
+gctt_refresh_menu (GncCombott *combott, GtkTreeModel *model)
+{
+    GncCombottPrivate *priv;
+
+    g_return_if_fail (GNC_IS_COMBOTT (combott));
+    g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
+
+    priv = GNC_COMBOTT_GET_PRIVATE (combott);
+
+    gctt_rebuild_menu(combott, model);
+}
+
+
+static void
+gctt_changed(GncCombott *combott)
+{
+/*
+g_print("Changed Signal\n");
+*/
+}
+
+
+static void
+gctt_combott_menu_position (GtkMenu  *menu,
+			   gint     *x,
+			   gint     *y,
+			   gint     *push_in,
+			   gpointer  user_data)
+{
+    GncCombott *combott = GNC_COMBOTT (user_data);
+    GncCombottPrivate *priv = GNC_COMBOTT_GET_PRIVATE (combott);
+    gint sx, sy;
+    GtkWidget *child;
+    GtkRequisition req;
+ 
+    child = GTK_BIN (priv->button)->child;
+
+    sx = sy = 0;
+
+    if (!gtk_widget_get_has_window (child))
+    {
+        sx += child->allocation.x;
+        sy += child->allocation.y;
+    }
+
+    gdk_window_get_root_coords (child->window, sx, sy, &sx, &sy);
+
+    sx -= GTK_WIDGET (priv->button)->style->xthickness;
+
+    gtk_widget_size_request (GTK_WIDGET (menu), &req);
+
+    if (gtk_widget_get_direction (GTK_WIDGET (priv->button)) == GTK_TEXT_DIR_LTR)
+        *x = sx;
+    else
+        *x = sx + child->allocation.width - req.width;
+
+    if(priv->active == -1 || priv->active == 0)
+        *y = sy;
+    else
+        *y = sy - ((req.height / priv->num_items) * (priv->active - 1));
+
+   *push_in = FALSE;
+}
+
+
+static void
+button_getsize_cb (GtkWidget *widget, GtkAllocation *allocation, gpointer *user_data)
+{
+    GncCombott *combott = GNC_COMBOTT (user_data);
+    GncCombottPrivate *priv = GNC_COMBOTT_GET_PRIVATE (combott);
+
+    priv->width = allocation->width;
+    priv->height = allocation->height;
+    priv->x = allocation->x;
+    priv->y = allocation->y;
+}
+
+
+static void
+menu_getsize_cb (GtkWidget *widget, GtkAllocation *allocation, gpointer *user_data)
+{
+    GncCombott *combott = GNC_COMBOTT (user_data);
+    GncCombottPrivate *priv = GNC_COMBOTT_GET_PRIVATE (combott);
+
+    /* Set the menu width */
+    gtk_widget_set_size_request (widget, priv->width - 6, allocation->height);
+}
+
+
+static gboolean
+which_tooltip_cb (GtkWidget  *widget, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip, gpointer user_data) 
+{
+    gchar *text = "";
+
+    GncCombott *combott = GNC_COMBOTT (user_data);
+    GncCombottPrivate *priv = GNC_COMBOTT_GET_PRIVATE (combott);
+
+    if(!priv->active == 0)
+    {
+        gtk_tree_model_get( priv->model, &priv->active_iter, priv->tip_col, &text, -1 );
+        if(g_strcmp0(text, "") && (text != NULL))
+        {
+            gchar *label = "";
+            gtk_tooltip_set_text (tooltip, text);
+            g_free(text);
+            return TRUE;
+        }
+        else
+        {
+            g_free(text);
+            return FALSE;
+        }
+    }
+   return FALSE;
+}
+
+
+static gboolean
+button_press_cb (GtkWidget *widget, GdkEvent *event, gpointer *user_data )
+{
+    GncCombott *combott = GNC_COMBOTT (user_data);
+    GncCombottPrivate *priv = GNC_COMBOTT_GET_PRIVATE (combott);
+
+    if(priv->model != NULL)
+    {
+        if (event->type == GDK_BUTTON_PRESS) {
+            GdkEventButton *bevent = (GdkEventButton *) event;
+
+            gtk_menu_popup (GTK_MENU (priv->menu),
+		  NULL, NULL,
+		  gctt_combott_menu_position, combott,
+		  bevent->button, bevent->time);
+
+            /* Tell calling code that we have handled this event; the buck
+             * stops here. */
+            return TRUE;
+        }
+    }
+    /* Tell calling code that we have not handled this event; pass it on. */
+    return FALSE;
+}
+
+
+static void
+menuitem_response_cb (GtkMenuItem *item, gpointer *user_data )
+{
+    const gchar *label_text;
+    GtkTreeIter iter, iter_now;
+    gboolean valid;
+    gint active = 1;
+    gint active_now = 1;
+
+    GncCombott *combott = GNC_COMBOTT (user_data);
+    GncCombottPrivate *priv = GNC_COMBOTT_GET_PRIVATE (combott);
+
+    label_text = gtk_menu_item_get_label (item);
+
+    /* Set the button Label */
+    gtk_label_set_text(GTK_LABEL(priv->label), label_text);
+    gtk_misc_set_alignment (GTK_MISC(priv->label), 0, 0.5);
+
+    /* Get the coresponding entry in the list store */
+    valid = gtk_tree_model_get_iter_first (priv->model, &iter);
+    while (valid)
+    {
+        /* Walk through the list, reading each row */
+        gchar *str_data;
+        gchar *tip_data;
+        gtk_tree_model_get (priv->model, &iter,
+                          priv->text_col, &str_data,
+                          priv->tip_col, &tip_data,
+                         -1);
+        if(!g_strcmp0(str_data, label_text))
+        {
+            active_now = active;
+            iter_now = iter;
+        }
+
+        g_free (str_data);
+        g_free (tip_data);
+        active ++;
+        valid = gtk_tree_model_iter_next (priv->model, &iter);
+    }
+
+    /* Emit Changed signal if we have selected a new entry */
+    if(priv->active != active_now)
+    {
+        priv->active = active_now;
+        priv->active_iter = iter_now;
+
+        g_signal_emit (combott, combott_signals[CHANGED], 0);
+    }
+}
+
+
+GncCombott *
+gnc_combott_new (void)
+{
+    GObject *hbox;
+    hbox = g_object_new (GNC_TYPE_COMBOTT, NULL);
+    return GNC_COMBOTT (hbox);
+}
+
+
+gint
+gnc_combott_get_active (GncCombott *combott)
+{
+    GncCombottPrivate *priv;
+    gint result;
+
+    g_return_val_if_fail (GNC_IS_COMBOTT (combott), 0);
+
+    priv = GNC_COMBOTT_GET_PRIVATE (combott);
+
+    result = priv->active - 1;
+
+    return result;
+}
+
+
+void
+gnc_combott_set_active (GncCombott *combott, gint index)
+{
+    GncCombottPrivate *priv;
+    GtkTreeIter iter;
+    gboolean valid = TRUE;
+    gint active = 1;
+    gint num = 1;
+
+    g_return_if_fail (GNC_IS_COMBOTT (combott));
+    g_return_if_fail (index >= -1);
+
+    priv = GNC_COMBOTT_GET_PRIVATE (combott);
+
+    /* Do we have a valid model */
+    if (priv->model != NULL)
+    {
+        /* Is index the same as current option */
+        if(index + 1 != priv->active)
+        {
+            /* Set button label to blank for no selection */
+            if(index == -1)
+            {
+                priv->active = 0;
+                gtk_label_set_text(GTK_LABEL(priv->label), "");
+                g_signal_emit (combott, combott_signals[CHANGED], 0);
+            }
+            else
+            {
+                /* Get the coresponding entry in the list store */
+                valid = gtk_tree_model_get_iter_first (priv->model, &iter);
+                while (valid)
+                {
+                    /* Walk through the list, reading each row */
+                    gchar *str_data;
+                    gchar *tip_data;
+                    /* Make sure you terminate calls to gtk_tree_model_get()
+                     * with a '-1' value */
+                    gtk_tree_model_get (priv->model, &iter,
+                                  priv->text_col, &str_data,
+                                  priv->tip_col, &tip_data,
+                                 -1);
+
+                    if(index + 1 == active)
+                    {
+                        priv->active = index + 1;
+                        priv->active_iter = iter;
+                        gtk_label_set_text(GTK_LABEL(priv->label), str_data);
+                        gtk_misc_set_alignment (GTK_MISC(priv->label), 0, 0.5);
+                        g_signal_emit (combott, combott_signals[CHANGED], 0);
+                    }
+
+                    g_free (str_data);
+                    g_free (tip_data);
+                    active ++;
+                    valid = gtk_tree_model_iter_next (priv->model, &iter);
+                }
+            }
+        }
+    }
+}

Added: gnucash/trunk/src/gnome-utils/gnc-combott.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-combott.h	                        (rev 0)
+++ gnucash/trunk/src/gnome-utils/gnc-combott.h	2012-08-01 13:53:58 UTC (rev 22274)
@@ -0,0 +1,66 @@
+/********************************************************************\
+ * gnc-combott.h -- Basic simulation of ComboBox with tooltips for  *
+ *                  each item.                                      *
+ * Copyright (c) 2012 Robert Fewell                                 *
+ *                                                                  *
+ *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
+ * This widget requires external ListStore which has two columns.   *
+ * By default, column 0 holds the text to display and column 1 the  *
+ * per item tooltip but these can be specified if the liststore has *
+ * a different format.                                              *
+ *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+\********************************************************************/
+
+#ifndef __GNC_COMBOTT_H__
+#define __GNC_COMBOTT_H__
+
+/* type macros */
+#define GNC_TYPE_COMBOTT            (gnc_combott_get_type ())
+#define GNC_COMBOTT(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_COMBOTT, GncCombott))
+#define GNC_COMBOTT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_COMBOTT, GncCombottClass))
+#define GNC_IS_COMBOTT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_COMBOTT))
+#define GNC_IS_COMBOTT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_COMBOTT))
+#define GNC_COMBOTT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_COMBOTT, GncCombottClass))
+#define GNC_COMBOTT_NAME            "GncCombott"
+
+/* typedefs & structures */
+typedef struct _GncCombott      GncCombott;
+typedef struct _GncCombottClass GncCombottClass;
+
+struct _GncCombott
+{
+    GtkHBox hbox;
+};
+
+struct _GncCombottClass
+{
+    GtkButtonClass parent;
+    void   (* changed) (GncCombott *combott);
+};
+
+/* Standard g_object type */
+GType            gnc_combott_get_type (void);
+GncCombott	*gnc_combott_new (void);
+
+gint             gnc_combott_get_active       (GncCombott *combott);
+void             gnc_combott_set_active       (GncCombott *combott, gint index);
+
+#endif /* __GNC_COMBOTT_H__ */
+

Modified: gnucash/trunk/src/import-export/import-format-dialog.c
===================================================================
--- gnucash/trunk/src/import-export/import-format-dialog.c	2012-07-27 15:49:51 UTC (rev 22273)
+++ gnucash/trunk/src/import-export/import-format-dialog.c	2012-08-01 13:53:58 UTC (rev 22274)
@@ -29,95 +29,100 @@
 
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
-
+#include "dialog-utils.h"
 #include "import-parse.h"
-#include "dialog-utils.h"
 #include "gnc-ui-util.h"
 
 #define MAX_CHOICES 6
 
-#ifdef GTKCOMBOBOX_TOOLTIPS_WORK
 static void
-choice_option_changed (GtkWidget *widget, gpointer index_p)
+option_changed_cb (GtkWidget *widget, gpointer index_p)
 {
-}
-#else
-static void
-choice_option_changed (GtkWidget *widget, gint index, gpointer index_p)
-{
     gint *my_index = index_p;
-    *my_index = index;
+    *my_index = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
 }
-#endif
 
+
 static GncImportFormat
 add_menu_and_run_dialog(GtkWidget *dialog, GtkWidget *menu_box, GncImportFormat fmt)
 {
-    GtkWidget *menu;
+    GtkComboBox  *combo;
+    GtkListStore *store;
+    GtkTreeIter iter;
+    GtkCellRenderer *cell;
     gint index = 0, count = 0;
+    gint *index_p = &index;
     GncImportFormat formats[MAX_CHOICES];
-    GNCOptionInfo menus[MAX_CHOICES];
 
-    memset(&menus, 0, sizeof(menus));
+    store = gtk_list_store_new(1, G_TYPE_STRING);
 
     if (fmt & GNCIF_NUM_PERIOD)
     {
+        gtk_list_store_append (store, &iter);
+        gtk_list_store_set (store, &iter, 0, _("Period: 123,456.78"), -1);
         formats[count] = GNCIF_NUM_PERIOD;
-        menus[count].name = _("Period: 123,456.78");
-        menus[count].callback = choice_option_changed;
-        menus[count].user_data = &index;
         count++;
     }
 
     if (fmt & GNCIF_NUM_COMMA)
     {
+        gtk_list_store_append (store, &iter);
+        gtk_list_store_set (store, &iter, 0, _("Comma: 123.456,78"), -1);
         formats[count] = GNCIF_NUM_COMMA;
-        menus[count].name = _("Comma: 123.456,78");
-        menus[count].callback = choice_option_changed;
-        menus[count].user_data = &index;
         count++;
     }
 
     if (fmt & GNCIF_DATE_MDY)
     {
+        gtk_list_store_append (store, &iter);
+        gtk_list_store_set (store, &iter, 0, _("m/d/y"), -1);
         formats[count] = GNCIF_DATE_MDY;
-        menus[count].name = _("m/d/y");
-        menus[count].callback = choice_option_changed;
-        menus[count].user_data = &index;
         count++;
     }
 
     if (fmt & GNCIF_DATE_DMY)
     {
+        gtk_list_store_append (store, &iter);
+        gtk_list_store_set (store, &iter, 0, _("d/m/y"), -1);
         formats[count] = GNCIF_DATE_DMY;
-        menus[count].name = _("d/m/y");
-        menus[count].callback = choice_option_changed;
-        menus[count].user_data = &index;
         count++;
     }
 
     if (fmt & GNCIF_DATE_YMD)
     {
+        gtk_list_store_append (store, &iter);
+        gtk_list_store_set (store, &iter, 0, _("y/m/d"), -1);
         formats[count] = GNCIF_DATE_YMD;
-        menus[count].name = _("y/m/d");
-        menus[count].callback = choice_option_changed;
-        menus[count].user_data = &index;
         count++;
     }
 
     if (fmt & GNCIF_DATE_YDM)
     {
+        gtk_list_store_append (store, &iter);
+        gtk_list_store_set (store, &iter, 0, _("y/d/m"), -1);
         formats[count] = GNCIF_DATE_YDM;
-        menus[count].name = _("y/d/m");
-        menus[count].callback = choice_option_changed;
-        menus[count].user_data = &index;
         count++;
     }
 
     g_assert(count > 1);
-    menu = gnc_build_option_menu(menus, count);
-    gtk_box_pack_start(GTK_BOX(menu_box), menu, TRUE, TRUE, 0);
 
+    combo = GTK_COMBO_BOX(gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)));
+    g_object_unref(store);
+
+    /* Create cell renderer. */
+    cell = gtk_cell_renderer_text_new();
+
+    /* Pack it to the combo box. */
+    gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( combo ), cell, FALSE );
+
+    /* Connect renderer to data source */
+    gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( combo ), cell, "text", 0, NULL );
+
+    g_signal_connect(G_OBJECT(combo), "changed",
+                         G_CALLBACK(option_changed_cb), index_p);
+
+    gtk_box_pack_start(GTK_BOX(menu_box), GTK_WIDGET(combo), TRUE, TRUE, 0);
+
     gtk_widget_show_all(dialog);
     gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
     gtk_dialog_run(GTK_DIALOG(dialog));
@@ -126,9 +131,9 @@
     return formats[index];
 }
 
+
 GncImportFormat
 gnc_import_choose_fmt(const char* msg, GncImportFormat fmts, gpointer data)
-
 {
     GtkBuilder *builder;
     GtkWidget *dialog;



More information about the gnucash-changes mailing list