r18719 - gnucash/trunk/src - Move two gtk-dependent files from src/core-utils to src/gnome-utils.

Christian Stimming cstim at code.gnucash.org
Wed Feb 24 14:14:02 EST 2010


Author: cstim
Date: 2010-02-24 14:14:02 -0500 (Wed, 24 Feb 2010)
New Revision: 18719
Trac: http://svn.gnucash.org/trac/changeset/18719

Added:
   gnucash/trunk/src/gnome-utils/gnc-gobject-utils.c
   gnucash/trunk/src/gnome-utils/gnc-gobject-utils.h
   gnucash/trunk/src/gnome-utils/gnc-gtk-utils.c
   gnucash/trunk/src/gnome-utils/gnc-gtk-utils.h
Removed:
   gnucash/trunk/src/core-utils/gnc-gobject-utils.c
   gnucash/trunk/src/core-utils/gnc-gobject-utils.h
   gnucash/trunk/src/core-utils/gnc-gtk-utils.c
   gnucash/trunk/src/core-utils/gnc-gtk-utils.h
Modified:
   gnucash/trunk/src/core-utils/Makefile.am
   gnucash/trunk/src/gnome-utils/Makefile.am
Log:
Move two gtk-dependent files from src/core-utils to src/gnome-utils.

core-utils depends on glib and additionally guile and gconf, but
not (yet) gtk. Those two files which do are moved to the next
module which already depends on gtk, which is gnome-utils.

Modified: gnucash/trunk/src/core-utils/Makefile.am
===================================================================
--- gnucash/trunk/src/core-utils/Makefile.am	2010-02-24 18:30:30 UTC (rev 18718)
+++ gnucash/trunk/src/core-utils/Makefile.am	2010-02-24 19:14:02 UTC (rev 18719)
@@ -6,24 +6,19 @@
   gnc-gdate-utils.c \
   gnc-gkeyfile-utils.c \
   gnc-glib-utils.c \
-  gnc-gobject-utils.c \
-  swig-core-utils.c \
-  gnc-gtk-utils.c
+  swig-core-utils.c
 
 libgnc_core_utils_la_LIBADD = \
   ${GUILE_LIBS} \
   ${GLIB_LIBS} \
-  ${GCONF_LIBS} \
-  ${GTK_LIBS}
+  ${GCONF_LIBS}
 
 noinst_HEADERS = \
   gnc-main.h \
   gnc-gconf-utils.h \
   gnc-gdate-utils.h \
   gnc-gkeyfile-utils.h \
-  gnc-glib-utils.h \
-  gnc-gobject-utils.h \
-  gnc-gtk-utils.h
+  gnc-glib-utils.h
 
 if BUILDING_FROM_SVN
 swig-core-utils.c: core-utils.i ${top_srcdir}/src/base-typemaps.i
@@ -35,7 +30,6 @@
   ${GUILE_INCS} \
   ${GLIB_CFLAGS} \
   ${GCONF_CFLAGS} \
-  ${GTK_CFLAGS} \
   -I${top_srcdir}/src
 
 

Deleted: gnucash/trunk/src/core-utils/gnc-gobject-utils.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-gobject-utils.c	2010-02-24 18:30:30 UTC (rev 18718)
+++ gnucash/trunk/src/core-utils/gnc-gobject-utils.c	2010-02-24 19:14:02 UTC (rev 18719)
@@ -1,240 +0,0 @@
-/*
- * gnc-gobject-utils.h -- utility functions for working
- *                        with GObjects
- * Copyright (C) 2005 David Hampton <hampton at employees.org>
- *
- * 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 "config.h"
-
-#include <stdio.h>
-#include "gnc-gobject-utils.h"
-
-#include <gtk/gtk.h>	// For gtk_main_quit(). Can't get this to work with
-// a g_source attached to the main glib context.
-
-
-static void gnc_gobject_weak_cb (gpointer user_data, GObject *object);
-
-/************************************************************/
-/*                      Gconf Utilities                     */
-/************************************************************/
-
-
-/** Get a pointer to the hash table used by the tracking database.  If
- *  the hash table doesn't exist, it will be created.  If gnucash was
- *  compiled with --enable-ref-count-dumps, this funtion is also the
- *  point where the gnc_gobject_tracking_dump() function is registered
- *  to be called the GTK exits.
- *
- *  @internal.
- */
-static GHashTable*
-gnc_gobject_tracking_table (void)
-{
-    static GHashTable *singleton = NULL;
-
-    if (!singleton)
-    {
-        singleton = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
-#if DEBUG_REFERENCE_COUNTING
-        gtk_quit_add (0, (GtkFunction)gnc_gobject_tracking_dump, NULL);
-#endif
-    }
-    return singleton;
-}
-
-
-/** Dump a single object from the tracking database.  This is an
- *  auxiliary function used by the gnc_gobject_tracking_dump()
- *  function.  This function currently only dumps the object pointer
- *  and the reference count.  It can be extended, if necessary, via
- *  object introspection.
- *
- *  @internal.
- */
-static void
-gnc_gobject_dump_gobject (GObject *object, const gchar *name)
-{
-    //printf("Enter %s: object %p, name %s\n", G_STRFUNC, object, name);
-    g_message("    object %p, ref count %d", object, object->ref_count);
-    //printf("Leave %s:\n", G_STRFUNC);
-}
-
-
-/** Dump a single list of objects from the tracking database.  This is
- *  an auxiliary function used by the gnc_gobject_tracking_dump()
- *  function.
- *
- *  @internal.
- */
-static gboolean
-gnc_gobject_dump_list (const gchar *name, GList *list, gpointer user_data)
-{
-    //printf("Enter %s: name %s, list %p\n", G_STRFUNC, name, list);
-    g_message("  %d %s", g_list_length(list), name);
-    g_list_foreach(list, (GFunc)gnc_gobject_dump_gobject, (gpointer)name);
-    //printf("Leave %s:\n", G_STRFUNC);
-    return TRUE;
-}
-
-
-/** Dump the entire object tracking database via the g_log() family of
- *  functions.  This function is only called when gnucash exits, and
- *  at that point all of the objects should have been removed from the
- *  database and freed.  Any object remaining is the result of a
- *  memory/object leakage.
- */
-void
-gnc_gobject_tracking_dump (void)
-{
-    GHashTable *table;
-
-    //printf("Enter %s:\n", G_STRFUNC);
-    table = gnc_gobject_tracking_table();
-
-    if (g_hash_table_size(table) > 0)
-    {
-        g_message("The following objects remain alive:");
-        g_hash_table_foreach_remove(table, (GHRFunc)gnc_gobject_dump_list, NULL);
-    }
-    //printf("Leave %s:\n", G_STRFUNC);
-}
-
-
-/** Tell gnucash to remember this object in the database.
- */
-void
-gnc_gobject_tracking_remember (GObject *object, GObjectClass *klass)
-{
-    GHashTable *table;
-    GList *list;
-    const gchar *name;
-
-    g_return_if_fail(G_IS_OBJECT(object));
-
-    /* Little dance here to handle startup conditions. During object
-     * initialization the object type changes as each each parent class
-     * is initialized.  The class passed to the initialization function
-     * is always the ultimate class of the object. */
-    if (klass == NULL)
-        klass = G_OBJECT_GET_CLASS(object);
-    name = g_type_name(G_TYPE_FROM_CLASS(klass));
-
-    //printf("Enter %s: object %p of type %s\n", G_STRFUNC, object, name);
-    table = gnc_gobject_tracking_table();
-    list = g_hash_table_lookup(table, name);
-
-    if (g_list_index(list, object) != -1)
-    {
-        g_critical("Object %p is already in list of %s", object, name);
-        //printf("Leave %s: already in list\n", G_STRFUNC);
-        return;
-    }
-
-    list = g_list_append(list, object);
-    g_hash_table_insert(table, g_strdup(name), list);
-
-    g_object_weak_ref(object, gnc_gobject_weak_cb, NULL);
-    //printf("Leave %s:\n", G_STRFUNC);
-}
-
-
-static gboolean
-gnc_gobject_tracking_forget_internal (GObject *object)
-{
-    GHashTable *table;
-    GList *list, *item;
-    const gchar *name;
-
-    g_return_val_if_fail(G_IS_OBJECT(object), FALSE);
-
-    name = G_OBJECT_TYPE_NAME(object);
-    //printf("Enter %s: object %p of type %s\n", G_STRFUNC, object, name);
-    table = gnc_gobject_tracking_table();
-    list = g_hash_table_lookup(table, name);
-    if (!list)
-    {
-        //printf("Leave %s: list for %s objects not found.\n", G_STRFUNC, name);
-        return FALSE;
-    }
-
-    item = g_list_find(list, object);
-    if (!item)
-    {
-        //printf("Leave %s: object %p not in %s object list.\n", G_STRFUNC,
-        //       object, name);
-        return FALSE;
-    }
-
-    list = g_list_remove_link(list, item);
-    if (list)
-    {
-        g_hash_table_replace(table, g_strdup(name), list);
-        //printf("Leave %s: object removed.\n", G_STRFUNC);
-    }
-    else
-    {
-        g_hash_table_remove(table, name);
-        //printf("Leave %s: object and list removed.\n", G_STRFUNC);
-    }
-    return TRUE;
-}
-
-
-/** Tell gnucash to remember this object in the database.
- */
-void
-gnc_gobject_tracking_forget (GObject *object)
-{
-    if (gnc_gobject_tracking_forget_internal(object))
-        g_object_weak_unref(object, gnc_gobject_weak_cb, NULL);
-}
-
-
-/** This callback function is called when a remembered object is
- *  destroyed.  It is used to catch the destruction an object when the
- *  caller didn't first tell this code to forget that object.  No need
- *  for an error message, just forget the object.
- *
- *  @internal
- *
- *  @param object The object being destroyed.
- */
-static void
-gnc_gobject_weak_cb (gpointer user_data, GObject *object)
-{
-    gnc_gobject_tracking_forget_internal(object);
-}
-
-
-/** Get a list of all known objects of a specified type.
- */
-const GList *
-gnc_gobject_tracking_get_list (const gchar *name)
-{
-    GHashTable *table;
-    GList *list;
-
-    //printf("Enter %s: name %s\n", G_STRFUNC, name);
-    table = gnc_gobject_tracking_table();
-    list = g_hash_table_lookup(table, name);
-    //printf("Leave %s: list %p\n", G_STRFUNC, list);
-    return list;
-}

Deleted: gnucash/trunk/src/core-utils/gnc-gobject-utils.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-gobject-utils.h	2010-02-24 18:30:30 UTC (rev 18718)
+++ gnucash/trunk/src/core-utils/gnc-gobject-utils.h	2010-02-24 19:14:02 UTC (rev 18719)
@@ -1,115 +0,0 @@
-/*
- * gnc-gobject-utils.h -- utility functions for working
- *                        with GObjects
- * Copyright (C) 2005 David Hampton <hampton at employees.org>
- *
- * 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
- */
-
-/** @addtogroup GLib
-    @{ */
-/** @addtogroup Gobject
-    @{ */
-
-/** @file gnc-gobject-utils.h
- *  @brief Gobject helper routines.
- *  @author Copyright (C) 2005 David Hampton <hampton at employees.org>
- *
- *  The APIs in this file are designed to provide additional
- *  functionality to GObjects, or to make it easier to use the Gobject
- *  system from within Gnucash.
- */
-
-#ifndef GNC_GOBJECT_UTILS_H
-#define GNC_GOBJECT_UTILS_H
-
-#include <glib.h>
-#include <glib-object.h>
-
-/** @name Gobject Tracking Functions
- *  @{
- *
- *  This set of functions is used to maintain a "database" of objects
- *  that are built on top of a GObject (any level of nesting).  This
- *  database is simply a hash table of lists.  The hash table takes
- *  the object name as its key and returns a list of all objects of
- *  that type.  The object is then added to, deleted from, or looked
- *  up in the list.  The database can also be queried for a list of
- *  all objects of a specified type.  This can be used to find
- *  pre-existing GncTreeModels, etc.  (In this case performing a
- *  search for a specific object wouldn't help because the information
- *  being inspected is private to the object.)
- *
- *  Any object added to this databasse during the execution of gnucash
- *  should be deleted from it before completion of the program.  WHen
- *  the program shuts down, a list of all abjects still in the
- *  database will be dumped out to the logfile.  This should help
- *  developers find memoty leaks in their code where an object is
- *  lost, or is not release because it gained an extra reference at
- *  some point during its lifetime.
- */
-
-
-/** Tell gnucash to remember this object in the database.
- *
- *  @param object The object to be tracked.  This can be a fully or
- *  partially instantiated object.
- *
- *  @param klass The class structure for the object.  This argument
- *  may be NULL if a fully instantiated object is passed in as the
- *  first argument.  If a partially instantiated object is provided
- *  (I.E. a parent class called this function) then this argument is
- *  required.  This is necessary because the class of the object
- *  changes as each of the parent class is instantiated.  The class
- *  structure, however, status constant and always reflects the fully
- *  instantiated object.
- */
-void gnc_gobject_tracking_remember (GObject *object, GObjectClass *klass);
-
-/** Tell gnucash to drop this object from the database.
- *
- *  @param object The object to be dropped.
- */
-void gnc_gobject_tracking_forget (GObject *object);
-
-/** Get a list of all known objects of a specified type.
- *
- *  @param name The type name of the objects to be found.  This is the
- *  name used when the object type was initialized.  If unknown, it
- *  can be found by calling G_OBJECT_TYPE_NAME(object).
- *
- *  @return A GList of objects of the specified type.  This list is
- *  owned by the tracking code and must not be modified by the caller.
- */
-const GList *gnc_gobject_tracking_get_list (const gchar *name);
-
-
-/** Dump the entire object tracking database via the g_log() family of
- *  functions.  This function is only called when gnucash exits, and
- *  at that point all of the objects should have been removed from the
- *  database and freed.  Any object remaining is the result of a
- *  memory/object leakage.
- */
-void gnc_gobject_tracking_dump (void);
-
-/** @} */
-
-
-#endif /* GNC_GOBJECT_UTILS_H */
-/** @} */
-/** @} */

Deleted: gnucash/trunk/src/core-utils/gnc-gtk-utils.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-gtk-utils.c	2010-02-24 18:30:30 UTC (rev 18718)
+++ gnucash/trunk/src/core-utils/gnc-gtk-utils.c	2010-02-24 19:14:02 UTC (rev 18719)
@@ -1,225 +0,0 @@
-/********************************************************************\
- * gnc-gtk-utils.c -- utility functions based on glib functions     *
- * Copyright (C) 2006 David Hampton <hampton at employees.org>         *
- *                                                                  *
- * 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 "config.h"
-
-#include "gnc-gtk-utils.h"
-
-#define LAST_INDEX "last_index"
-#define CHANGED_ID "changed_id"
-
-
-/** Find an entry in the GtkComboBoxEntry by its text value, and set
- *  the widget to that value.  This function also records the index of
- *  that text value for use when the user leaves the widget.
- *
- *  @param cbe A pointer to a GtkComboBoxEntry widget.
- *
- *  @param text The entry text to find in the model of the combo box
- *  entry. */
-void
-gnc_cbe_set_by_string(GtkComboBoxEntry *cbe,
-                      const gchar *text)
-{
-    GtkTreeModel *model;
-    GtkTreeIter iter;
-    gchar *tree_string;
-    gint column, index, id;
-    gboolean match;
-
-    model = gtk_combo_box_get_model(GTK_COMBO_BOX(cbe));
-    if (!gtk_tree_model_get_iter_first(model, &iter))
-    {
-        /* empty tree */
-        gtk_combo_box_set_active(GTK_COMBO_BOX(cbe), -1);
-        return;
-    }
-
-    column = gtk_combo_box_entry_get_text_column(cbe);
-    do
-    {
-        gtk_tree_model_get(model, &iter, column, &tree_string, -1);
-        match = g_utf8_collate(text, tree_string) == 0;
-        g_free(tree_string);
-        if (!match)
-            continue;
-
-        /* Found a matching string */
-        id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cbe), CHANGED_ID));
-        g_signal_handler_block(cbe, id);
-        gtk_combo_box_set_active_iter(GTK_COMBO_BOX(cbe), &iter);
-        g_signal_handler_unblock(cbe, id);
-
-        index = gtk_combo_box_get_active(GTK_COMBO_BOX(cbe));
-        g_object_set_data(G_OBJECT(cbe), LAST_INDEX, GINT_TO_POINTER(index));
-        return;
-    }
-    while (gtk_tree_model_iter_next(model, &iter));
-}
-
-
-/**  The GtkComboBoxEntry widget has changed its value.  If the widget
- *   now points to another valid entry string then record the index of
- *   that string for use when the user leaves the widget.
- *
- *   @param widget Unused.
- *
- *   @param cbe A pointer to a GtkComboBoxEntry widget. */
-static void
-gnc_cbe_changed_cb (GtkComboBox *widget,
-                    GtkComboBoxEntry *cbe)
-{
-    gint index;
-
-    index = gtk_combo_box_get_active(widget);
-    if (index == -1)
-        return;
-    g_object_set_data(G_OBJECT(cbe), LAST_INDEX, GINT_TO_POINTER(index));
-}
-
-
-/**  The completion attached to currency edit widget has selected a
- *   match.  This function extracts the completed string from the
- *   completion code's temporary model, and uses that to set the index
- *   of that currency name for use when the user leaves the widget.
- *   This should always point to a valid currency name since the user
- *   made the selection from a list of currency names.
- *
- *   @param completion Unused.
- *
- *   @param comp_model A temporary model used by completion code that
- *   contains only the current matches.
- *
- *   @param comp_iter The iter in the completion's temporary model
- *   that represents the user selected match.
- *
- *   @param cbe A pointer to a currency entry widget. */
-static gboolean
-gnc_cbe_match_selected_cb (GtkEntryCompletion *completion,
-                           GtkTreeModel       *comp_model,
-                           GtkTreeIter        *comp_iter,
-                           GtkComboBoxEntry   *cbe)
-{
-    gint column;
-    gchar *text;
-
-    column = gtk_combo_box_entry_get_text_column(cbe);
-    gtk_tree_model_get(comp_model, comp_iter, column, &text, -1);
-    gnc_cbe_set_by_string(cbe, text);
-    g_free(text);
-    return FALSE;
-}
-
-
-/**  The focus left the currency edit widget, so reset the widget to
- *   its last known good value.  If the widget value contained a valid
- *   currency then this is a noop.  Otherwise the widget will be reset
- *   to the last user selected currency.  This latter state will occur
- *   if the user has typed characters directly into the widget but not
- *   selected a completion.
- *
- *   @param entry Unused.
- *
- *   @param event Unused.
- *
- *   @param cbe A pointer to a currency entry widget. */
-static gboolean
-gnc_cbe_focus_out_cb (GtkEntry *entry,
-                      GdkEventFocus *event,
-                      GtkComboBoxEntry *cbe)
-{
-    const gchar *text;
-    gint index;
-
-    /* Make a final attempt to match the current text. */
-    text = gtk_entry_get_text(entry);
-    gnc_cbe_set_by_string(cbe, text);
-
-    /* Get the last known index (which may have just been set). */
-    index = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cbe), LAST_INDEX));
-    gtk_combo_box_set_active(GTK_COMBO_BOX(cbe), index);
-    return FALSE;
-}
-
-void
-gnc_cbe_add_completion (GtkComboBoxEntry *cbe)
-{
-    GtkEntry *entry;
-    GtkEntryCompletion *completion;
-    GtkTreeModel *model;
-
-    entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(cbe)));
-    completion = gtk_entry_get_completion(entry);
-    if (completion)
-        return;
-
-    /* No completion yet? Set one up. */
-    completion = gtk_entry_completion_new();
-    model = gtk_combo_box_get_model(GTK_COMBO_BOX(cbe));
-    gtk_entry_completion_set_model(completion, model);
-    gtk_entry_completion_set_text_column(completion, 0);
-    gtk_entry_completion_set_inline_completion(completion, TRUE);
-    gtk_entry_set_completion(entry, completion);
-    g_object_unref(completion);
-}
-
-void
-gnc_cbe_require_list_item (GtkComboBoxEntry *cbe)
-{
-    GtkEntry *entry;
-    GtkEntryCompletion *completion;
-    GtkTreeModel *model;
-    GtkTreeIter iter;
-    gint index, id;
-
-    /* Ensure completion is set up. */
-    gnc_cbe_add_completion(cbe);
-
-    /* If an item in the combo box isn't already selected, then force
-     * select the first item. Take care, the combo box may not have been
-     * filled yet.  */
-    entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(cbe)));
-    completion = gtk_entry_get_completion(entry);
-    index = gtk_combo_box_get_active(GTK_COMBO_BOX(cbe));
-    if (index == -1)
-    {
-        model = gtk_entry_completion_get_model(completion);
-        if (gtk_tree_model_get_iter_first(model, &iter))
-        {
-            gtk_combo_box_set_active(GTK_COMBO_BOX(cbe), 0);
-            index = 0;
-        }
-    }
-    g_object_set_data(G_OBJECT(cbe), LAST_INDEX, GINT_TO_POINTER(index));
-
-    /* Now the signals to make sure the user can't leave the
-       widget without a valid currency. */
-    id = g_signal_connect(cbe, "changed",
-                          G_CALLBACK(gnc_cbe_changed_cb), cbe);
-    g_signal_connect(completion, "match_selected",
-                     G_CALLBACK(gnc_cbe_match_selected_cb), cbe);
-    g_signal_connect(entry, "focus-out-event",
-                     G_CALLBACK(gnc_cbe_focus_out_cb), cbe);
-
-    g_object_set_data(G_OBJECT(cbe), CHANGED_ID, GINT_TO_POINTER(id));
-}

Deleted: gnucash/trunk/src/core-utils/gnc-gtk-utils.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-gtk-utils.h	2010-02-24 18:30:30 UTC (rev 18718)
+++ gnucash/trunk/src/core-utils/gnc-gtk-utils.h	2010-02-24 19:14:02 UTC (rev 18719)
@@ -1,51 +0,0 @@
-/********************************************************************\
- * gnc-gtk-utils.c -- utility functions based on glib functions     *
- * Copyright (C) 2006 David Hampton <hampton at employees.org>         *
- *                                                                  *
- * 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                   *
- *                                                                  *
-\********************************************************************/
-
-/** @addtogroup Gtk Gtk Utilities
-
-    The API in this file is designed to provide support functions that
-    wrap the base gtk functions and make them easier to use.
-
-    @{ */
-/** @file gnc-gtk-utils.h
- *  @brief gtk helper routines.
- *  @author Copyright (C) 2006 David Hampton <hampton at employees.org>
- */
-
-#ifndef GNC_GTK_UTILS_H
-#define GNC_GTK_UTILS_H
-
-#include <gtk/gtk.h>
-
-/** @name gtk Miscellaneous Functions
- @{
-*/
-
-void gnc_cbe_set_by_string(GtkComboBoxEntry *cbe, const gchar *text);
-void gnc_cbe_add_completion (GtkComboBoxEntry *cbe);
-void gnc_cbe_require_list_item (GtkComboBoxEntry *cbe);
-
-/** @} */
-
-#endif /* GNC_GTK_UTILS_H */
-/** @} */

Modified: gnucash/trunk/src/gnome-utils/Makefile.am
===================================================================
--- gnucash/trunk/src/gnome-utils/Makefile.am	2010-02-24 18:30:30 UTC (rev 18718)
+++ gnucash/trunk/src/gnome-utils/Makefile.am	2010-02-24 19:14:02 UTC (rev 18719)
@@ -65,6 +65,8 @@
   gnc-recurrence.c \
   gnc-general-select.c \
   gnc-gnome-utils.c \
+  gnc-gobject-utils.c \
+  gnc-gtk-utils.c \
   gnc-gui-query.c \
   gnc-icons.c \
   gnc-main-window.c \
@@ -170,6 +172,8 @@
   gnc-druid-provider-edge-gnome.h \
   gnc-druid-provider-file-gnome.h \
   gnc-druid-provider-multifile-gnome.h \
+  gnc-gobject-utils.h \
+  gnc-gtk-utils.h \
   search-param.h
 
 libgncmod_gnome_utils_la_LDFLAGS = -avoid-version

Copied: gnucash/trunk/src/gnome-utils/gnc-gobject-utils.c (from rev 18718, gnucash/trunk/src/core-utils/gnc-gobject-utils.c)
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-gobject-utils.c	                        (rev 0)
+++ gnucash/trunk/src/gnome-utils/gnc-gobject-utils.c	2010-02-24 19:14:02 UTC (rev 18719)
@@ -0,0 +1,240 @@
+/*
+ * gnc-gobject-utils.h -- utility functions for working
+ *                        with GObjects
+ * Copyright (C) 2005 David Hampton <hampton at employees.org>
+ *
+ * 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 "config.h"
+
+#include <stdio.h>
+#include "gnc-gobject-utils.h"
+
+#include <gtk/gtk.h>	// For gtk_main_quit(). Can't get this to work with
+// a g_source attached to the main glib context.
+
+
+static void gnc_gobject_weak_cb (gpointer user_data, GObject *object);
+
+/************************************************************/
+/*                      Gconf Utilities                     */
+/************************************************************/
+
+
+/** Get a pointer to the hash table used by the tracking database.  If
+ *  the hash table doesn't exist, it will be created.  If gnucash was
+ *  compiled with --enable-ref-count-dumps, this funtion is also the
+ *  point where the gnc_gobject_tracking_dump() function is registered
+ *  to be called the GTK exits.
+ *
+ *  @internal.
+ */
+static GHashTable*
+gnc_gobject_tracking_table (void)
+{
+    static GHashTable *singleton = NULL;
+
+    if (!singleton)
+    {
+        singleton = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+#if DEBUG_REFERENCE_COUNTING
+        gtk_quit_add (0, (GtkFunction)gnc_gobject_tracking_dump, NULL);
+#endif
+    }
+    return singleton;
+}
+
+
+/** Dump a single object from the tracking database.  This is an
+ *  auxiliary function used by the gnc_gobject_tracking_dump()
+ *  function.  This function currently only dumps the object pointer
+ *  and the reference count.  It can be extended, if necessary, via
+ *  object introspection.
+ *
+ *  @internal.
+ */
+static void
+gnc_gobject_dump_gobject (GObject *object, const gchar *name)
+{
+    //printf("Enter %s: object %p, name %s\n", G_STRFUNC, object, name);
+    g_message("    object %p, ref count %d", object, object->ref_count);
+    //printf("Leave %s:\n", G_STRFUNC);
+}
+
+
+/** Dump a single list of objects from the tracking database.  This is
+ *  an auxiliary function used by the gnc_gobject_tracking_dump()
+ *  function.
+ *
+ *  @internal.
+ */
+static gboolean
+gnc_gobject_dump_list (const gchar *name, GList *list, gpointer user_data)
+{
+    //printf("Enter %s: name %s, list %p\n", G_STRFUNC, name, list);
+    g_message("  %d %s", g_list_length(list), name);
+    g_list_foreach(list, (GFunc)gnc_gobject_dump_gobject, (gpointer)name);
+    //printf("Leave %s:\n", G_STRFUNC);
+    return TRUE;
+}
+
+
+/** Dump the entire object tracking database via the g_log() family of
+ *  functions.  This function is only called when gnucash exits, and
+ *  at that point all of the objects should have been removed from the
+ *  database and freed.  Any object remaining is the result of a
+ *  memory/object leakage.
+ */
+void
+gnc_gobject_tracking_dump (void)
+{
+    GHashTable *table;
+
+    //printf("Enter %s:\n", G_STRFUNC);
+    table = gnc_gobject_tracking_table();
+
+    if (g_hash_table_size(table) > 0)
+    {
+        g_message("The following objects remain alive:");
+        g_hash_table_foreach_remove(table, (GHRFunc)gnc_gobject_dump_list, NULL);
+    }
+    //printf("Leave %s:\n", G_STRFUNC);
+}
+
+
+/** Tell gnucash to remember this object in the database.
+ */
+void
+gnc_gobject_tracking_remember (GObject *object, GObjectClass *klass)
+{
+    GHashTable *table;
+    GList *list;
+    const gchar *name;
+
+    g_return_if_fail(G_IS_OBJECT(object));
+
+    /* Little dance here to handle startup conditions. During object
+     * initialization the object type changes as each each parent class
+     * is initialized.  The class passed to the initialization function
+     * is always the ultimate class of the object. */
+    if (klass == NULL)
+        klass = G_OBJECT_GET_CLASS(object);
+    name = g_type_name(G_TYPE_FROM_CLASS(klass));
+
+    //printf("Enter %s: object %p of type %s\n", G_STRFUNC, object, name);
+    table = gnc_gobject_tracking_table();
+    list = g_hash_table_lookup(table, name);
+
+    if (g_list_index(list, object) != -1)
+    {
+        g_critical("Object %p is already in list of %s", object, name);
+        //printf("Leave %s: already in list\n", G_STRFUNC);
+        return;
+    }
+
+    list = g_list_append(list, object);
+    g_hash_table_insert(table, g_strdup(name), list);
+
+    g_object_weak_ref(object, gnc_gobject_weak_cb, NULL);
+    //printf("Leave %s:\n", G_STRFUNC);
+}
+
+
+static gboolean
+gnc_gobject_tracking_forget_internal (GObject *object)
+{
+    GHashTable *table;
+    GList *list, *item;
+    const gchar *name;
+
+    g_return_val_if_fail(G_IS_OBJECT(object), FALSE);
+
+    name = G_OBJECT_TYPE_NAME(object);
+    //printf("Enter %s: object %p of type %s\n", G_STRFUNC, object, name);
+    table = gnc_gobject_tracking_table();
+    list = g_hash_table_lookup(table, name);
+    if (!list)
+    {
+        //printf("Leave %s: list for %s objects not found.\n", G_STRFUNC, name);
+        return FALSE;
+    }
+
+    item = g_list_find(list, object);
+    if (!item)
+    {
+        //printf("Leave %s: object %p not in %s object list.\n", G_STRFUNC,
+        //       object, name);
+        return FALSE;
+    }
+
+    list = g_list_remove_link(list, item);
+    if (list)
+    {
+        g_hash_table_replace(table, g_strdup(name), list);
+        //printf("Leave %s: object removed.\n", G_STRFUNC);
+    }
+    else
+    {
+        g_hash_table_remove(table, name);
+        //printf("Leave %s: object and list removed.\n", G_STRFUNC);
+    }
+    return TRUE;
+}
+
+
+/** Tell gnucash to remember this object in the database.
+ */
+void
+gnc_gobject_tracking_forget (GObject *object)
+{
+    if (gnc_gobject_tracking_forget_internal(object))
+        g_object_weak_unref(object, gnc_gobject_weak_cb, NULL);
+}
+
+
+/** This callback function is called when a remembered object is
+ *  destroyed.  It is used to catch the destruction an object when the
+ *  caller didn't first tell this code to forget that object.  No need
+ *  for an error message, just forget the object.
+ *
+ *  @internal
+ *
+ *  @param object The object being destroyed.
+ */
+static void
+gnc_gobject_weak_cb (gpointer user_data, GObject *object)
+{
+    gnc_gobject_tracking_forget_internal(object);
+}
+
+
+/** Get a list of all known objects of a specified type.
+ */
+const GList *
+gnc_gobject_tracking_get_list (const gchar *name)
+{
+    GHashTable *table;
+    GList *list;
+
+    //printf("Enter %s: name %s\n", G_STRFUNC, name);
+    table = gnc_gobject_tracking_table();
+    list = g_hash_table_lookup(table, name);
+    //printf("Leave %s: list %p\n", G_STRFUNC, list);
+    return list;
+}

Copied: gnucash/trunk/src/gnome-utils/gnc-gobject-utils.h (from rev 18718, gnucash/trunk/src/core-utils/gnc-gobject-utils.h)
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-gobject-utils.h	                        (rev 0)
+++ gnucash/trunk/src/gnome-utils/gnc-gobject-utils.h	2010-02-24 19:14:02 UTC (rev 18719)
@@ -0,0 +1,115 @@
+/*
+ * gnc-gobject-utils.h -- utility functions for working
+ *                        with GObjects
+ * Copyright (C) 2005 David Hampton <hampton at employees.org>
+ *
+ * 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
+ */
+
+/** @addtogroup GLib
+    @{ */
+/** @addtogroup Gobject
+    @{ */
+
+/** @file gnc-gobject-utils.h
+ *  @brief Gobject helper routines.
+ *  @author Copyright (C) 2005 David Hampton <hampton at employees.org>
+ *
+ *  The APIs in this file are designed to provide additional
+ *  functionality to GObjects, or to make it easier to use the Gobject
+ *  system from within Gnucash.
+ */
+
+#ifndef GNC_GOBJECT_UTILS_H
+#define GNC_GOBJECT_UTILS_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+/** @name Gobject Tracking Functions
+ *  @{
+ *
+ *  This set of functions is used to maintain a "database" of objects
+ *  that are built on top of a GObject (any level of nesting).  This
+ *  database is simply a hash table of lists.  The hash table takes
+ *  the object name as its key and returns a list of all objects of
+ *  that type.  The object is then added to, deleted from, or looked
+ *  up in the list.  The database can also be queried for a list of
+ *  all objects of a specified type.  This can be used to find
+ *  pre-existing GncTreeModels, etc.  (In this case performing a
+ *  search for a specific object wouldn't help because the information
+ *  being inspected is private to the object.)
+ *
+ *  Any object added to this databasse during the execution of gnucash
+ *  should be deleted from it before completion of the program.  WHen
+ *  the program shuts down, a list of all abjects still in the
+ *  database will be dumped out to the logfile.  This should help
+ *  developers find memoty leaks in their code where an object is
+ *  lost, or is not release because it gained an extra reference at
+ *  some point during its lifetime.
+ */
+
+
+/** Tell gnucash to remember this object in the database.
+ *
+ *  @param object The object to be tracked.  This can be a fully or
+ *  partially instantiated object.
+ *
+ *  @param klass The class structure for the object.  This argument
+ *  may be NULL if a fully instantiated object is passed in as the
+ *  first argument.  If a partially instantiated object is provided
+ *  (I.E. a parent class called this function) then this argument is
+ *  required.  This is necessary because the class of the object
+ *  changes as each of the parent class is instantiated.  The class
+ *  structure, however, status constant and always reflects the fully
+ *  instantiated object.
+ */
+void gnc_gobject_tracking_remember (GObject *object, GObjectClass *klass);
+
+/** Tell gnucash to drop this object from the database.
+ *
+ *  @param object The object to be dropped.
+ */
+void gnc_gobject_tracking_forget (GObject *object);
+
+/** Get a list of all known objects of a specified type.
+ *
+ *  @param name The type name of the objects to be found.  This is the
+ *  name used when the object type was initialized.  If unknown, it
+ *  can be found by calling G_OBJECT_TYPE_NAME(object).
+ *
+ *  @return A GList of objects of the specified type.  This list is
+ *  owned by the tracking code and must not be modified by the caller.
+ */
+const GList *gnc_gobject_tracking_get_list (const gchar *name);
+
+
+/** Dump the entire object tracking database via the g_log() family of
+ *  functions.  This function is only called when gnucash exits, and
+ *  at that point all of the objects should have been removed from the
+ *  database and freed.  Any object remaining is the result of a
+ *  memory/object leakage.
+ */
+void gnc_gobject_tracking_dump (void);
+
+/** @} */
+
+
+#endif /* GNC_GOBJECT_UTILS_H */
+/** @} */
+/** @} */

Copied: gnucash/trunk/src/gnome-utils/gnc-gtk-utils.c (from rev 18718, gnucash/trunk/src/core-utils/gnc-gtk-utils.c)
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-gtk-utils.c	                        (rev 0)
+++ gnucash/trunk/src/gnome-utils/gnc-gtk-utils.c	2010-02-24 19:14:02 UTC (rev 18719)
@@ -0,0 +1,225 @@
+/********************************************************************\
+ * gnc-gtk-utils.c -- utility functions based on glib functions     *
+ * Copyright (C) 2006 David Hampton <hampton at employees.org>         *
+ *                                                                  *
+ * 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 "config.h"
+
+#include "gnc-gtk-utils.h"
+
+#define LAST_INDEX "last_index"
+#define CHANGED_ID "changed_id"
+
+
+/** Find an entry in the GtkComboBoxEntry by its text value, and set
+ *  the widget to that value.  This function also records the index of
+ *  that text value for use when the user leaves the widget.
+ *
+ *  @param cbe A pointer to a GtkComboBoxEntry widget.
+ *
+ *  @param text The entry text to find in the model of the combo box
+ *  entry. */
+void
+gnc_cbe_set_by_string(GtkComboBoxEntry *cbe,
+                      const gchar *text)
+{
+    GtkTreeModel *model;
+    GtkTreeIter iter;
+    gchar *tree_string;
+    gint column, index, id;
+    gboolean match;
+
+    model = gtk_combo_box_get_model(GTK_COMBO_BOX(cbe));
+    if (!gtk_tree_model_get_iter_first(model, &iter))
+    {
+        /* empty tree */
+        gtk_combo_box_set_active(GTK_COMBO_BOX(cbe), -1);
+        return;
+    }
+
+    column = gtk_combo_box_entry_get_text_column(cbe);
+    do
+    {
+        gtk_tree_model_get(model, &iter, column, &tree_string, -1);
+        match = g_utf8_collate(text, tree_string) == 0;
+        g_free(tree_string);
+        if (!match)
+            continue;
+
+        /* Found a matching string */
+        id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cbe), CHANGED_ID));
+        g_signal_handler_block(cbe, id);
+        gtk_combo_box_set_active_iter(GTK_COMBO_BOX(cbe), &iter);
+        g_signal_handler_unblock(cbe, id);
+
+        index = gtk_combo_box_get_active(GTK_COMBO_BOX(cbe));
+        g_object_set_data(G_OBJECT(cbe), LAST_INDEX, GINT_TO_POINTER(index));
+        return;
+    }
+    while (gtk_tree_model_iter_next(model, &iter));
+}
+
+
+/**  The GtkComboBoxEntry widget has changed its value.  If the widget
+ *   now points to another valid entry string then record the index of
+ *   that string for use when the user leaves the widget.
+ *
+ *   @param widget Unused.
+ *
+ *   @param cbe A pointer to a GtkComboBoxEntry widget. */
+static void
+gnc_cbe_changed_cb (GtkComboBox *widget,
+                    GtkComboBoxEntry *cbe)
+{
+    gint index;
+
+    index = gtk_combo_box_get_active(widget);
+    if (index == -1)
+        return;
+    g_object_set_data(G_OBJECT(cbe), LAST_INDEX, GINT_TO_POINTER(index));
+}
+
+
+/**  The completion attached to currency edit widget has selected a
+ *   match.  This function extracts the completed string from the
+ *   completion code's temporary model, and uses that to set the index
+ *   of that currency name for use when the user leaves the widget.
+ *   This should always point to a valid currency name since the user
+ *   made the selection from a list of currency names.
+ *
+ *   @param completion Unused.
+ *
+ *   @param comp_model A temporary model used by completion code that
+ *   contains only the current matches.
+ *
+ *   @param comp_iter The iter in the completion's temporary model
+ *   that represents the user selected match.
+ *
+ *   @param cbe A pointer to a currency entry widget. */
+static gboolean
+gnc_cbe_match_selected_cb (GtkEntryCompletion *completion,
+                           GtkTreeModel       *comp_model,
+                           GtkTreeIter        *comp_iter,
+                           GtkComboBoxEntry   *cbe)
+{
+    gint column;
+    gchar *text;
+
+    column = gtk_combo_box_entry_get_text_column(cbe);
+    gtk_tree_model_get(comp_model, comp_iter, column, &text, -1);
+    gnc_cbe_set_by_string(cbe, text);
+    g_free(text);
+    return FALSE;
+}
+
+
+/**  The focus left the currency edit widget, so reset the widget to
+ *   its last known good value.  If the widget value contained a valid
+ *   currency then this is a noop.  Otherwise the widget will be reset
+ *   to the last user selected currency.  This latter state will occur
+ *   if the user has typed characters directly into the widget but not
+ *   selected a completion.
+ *
+ *   @param entry Unused.
+ *
+ *   @param event Unused.
+ *
+ *   @param cbe A pointer to a currency entry widget. */
+static gboolean
+gnc_cbe_focus_out_cb (GtkEntry *entry,
+                      GdkEventFocus *event,
+                      GtkComboBoxEntry *cbe)
+{
+    const gchar *text;
+    gint index;
+
+    /* Make a final attempt to match the current text. */
+    text = gtk_entry_get_text(entry);
+    gnc_cbe_set_by_string(cbe, text);
+
+    /* Get the last known index (which may have just been set). */
+    index = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cbe), LAST_INDEX));
+    gtk_combo_box_set_active(GTK_COMBO_BOX(cbe), index);
+    return FALSE;
+}
+
+void
+gnc_cbe_add_completion (GtkComboBoxEntry *cbe)
+{
+    GtkEntry *entry;
+    GtkEntryCompletion *completion;
+    GtkTreeModel *model;
+
+    entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(cbe)));
+    completion = gtk_entry_get_completion(entry);
+    if (completion)
+        return;
+
+    /* No completion yet? Set one up. */
+    completion = gtk_entry_completion_new();
+    model = gtk_combo_box_get_model(GTK_COMBO_BOX(cbe));
+    gtk_entry_completion_set_model(completion, model);
+    gtk_entry_completion_set_text_column(completion, 0);
+    gtk_entry_completion_set_inline_completion(completion, TRUE);
+    gtk_entry_set_completion(entry, completion);
+    g_object_unref(completion);
+}
+
+void
+gnc_cbe_require_list_item (GtkComboBoxEntry *cbe)
+{
+    GtkEntry *entry;
+    GtkEntryCompletion *completion;
+    GtkTreeModel *model;
+    GtkTreeIter iter;
+    gint index, id;
+
+    /* Ensure completion is set up. */
+    gnc_cbe_add_completion(cbe);
+
+    /* If an item in the combo box isn't already selected, then force
+     * select the first item. Take care, the combo box may not have been
+     * filled yet.  */
+    entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(cbe)));
+    completion = gtk_entry_get_completion(entry);
+    index = gtk_combo_box_get_active(GTK_COMBO_BOX(cbe));
+    if (index == -1)
+    {
+        model = gtk_entry_completion_get_model(completion);
+        if (gtk_tree_model_get_iter_first(model, &iter))
+        {
+            gtk_combo_box_set_active(GTK_COMBO_BOX(cbe), 0);
+            index = 0;
+        }
+    }
+    g_object_set_data(G_OBJECT(cbe), LAST_INDEX, GINT_TO_POINTER(index));
+
+    /* Now the signals to make sure the user can't leave the
+       widget without a valid currency. */
+    id = g_signal_connect(cbe, "changed",
+                          G_CALLBACK(gnc_cbe_changed_cb), cbe);
+    g_signal_connect(completion, "match_selected",
+                     G_CALLBACK(gnc_cbe_match_selected_cb), cbe);
+    g_signal_connect(entry, "focus-out-event",
+                     G_CALLBACK(gnc_cbe_focus_out_cb), cbe);
+
+    g_object_set_data(G_OBJECT(cbe), CHANGED_ID, GINT_TO_POINTER(id));
+}

Copied: gnucash/trunk/src/gnome-utils/gnc-gtk-utils.h (from rev 18718, gnucash/trunk/src/core-utils/gnc-gtk-utils.h)
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-gtk-utils.h	                        (rev 0)
+++ gnucash/trunk/src/gnome-utils/gnc-gtk-utils.h	2010-02-24 19:14:02 UTC (rev 18719)
@@ -0,0 +1,51 @@
+/********************************************************************\
+ * gnc-gtk-utils.c -- utility functions based on glib functions     *
+ * Copyright (C) 2006 David Hampton <hampton at employees.org>         *
+ *                                                                  *
+ * 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                   *
+ *                                                                  *
+\********************************************************************/
+
+/** @addtogroup Gtk Gtk Utilities
+
+    The API in this file is designed to provide support functions that
+    wrap the base gtk functions and make them easier to use.
+
+    @{ */
+/** @file gnc-gtk-utils.h
+ *  @brief gtk helper routines.
+ *  @author Copyright (C) 2006 David Hampton <hampton at employees.org>
+ */
+
+#ifndef GNC_GTK_UTILS_H
+#define GNC_GTK_UTILS_H
+
+#include <gtk/gtk.h>
+
+/** @name gtk Miscellaneous Functions
+ @{
+*/
+
+void gnc_cbe_set_by_string(GtkComboBoxEntry *cbe, const gchar *text);
+void gnc_cbe_add_completion (GtkComboBoxEntry *cbe);
+void gnc_cbe_require_list_item (GtkComboBoxEntry *cbe);
+
+/** @} */
+
+#endif /* GNC_GTK_UTILS_H */
+/** @} */



More information about the gnucash-changes mailing list