2001-10-26 Christopher James Lahey <clahey@ximian.com> * e-cell-checkbox.c, e-cell-checkbox.h, e-cell-combo.c, e-cell-combo.h, e-cell-date.c, e-cell-date.h, e-cell-number.c, e-cell-number.h, e-cell-pixbuf.c, e-cell-pixbuf.h, e-cell-popup.c, e-cell-popup.h, e-cell-size.c, e-cell-size.h, e-cell-spin-button.c, e-cell-spin-button.h, e-cell-string.c, e-cell-text.c, e-cell-text.h, e-cell-toggle.c, e-cell-toggle.h, e-cell-tree.c, e-cell-tree.h, e-cell.c, e-cell.h, e-table-click-to-add.c, e-table-click-to-add.h, e-table-col-dnd.h, e-table-col.c, e-table-col.h, e-table-column-specification.c, e-table-column-specification.h, e-table-column.c, e-table-config-field.c, e-table-config-field.h, e-table-config.c, e-table-config.h, e-table-defines.h, e-table-example-1.c, e-table-example-2.c, e-table-extras.c, e-table-extras.h, e-table-field-chooser-dialog.c, e-table-field-chooser-dialog.h, e-table-field-chooser-item.c, e-table-field-chooser-item.h, e-table-field-chooser.c, e-table-field-chooser.h, e-table-group-container.c, e-table-group-container.h, e-table-group-leaf.c, e-table-group-leaf.h, e-table-group.c, e-table-group.h, e-table-header-item.c, e-table-header-item.h, e-table-header-utils.c, e-table-header-utils.h, e-table-header.c, e-table-header.h, e-table-item.c, e-table-item.h, e-table-memory-callbacks.c, e-table-memory-callbacks.h, e-table-memory.c, e-table-memory.h, e-table-model.c, e-table-model.h, e-table-one.c, e-table-one.h, e-table-scrolled.c, e-table-scrolled.h, e-table-selection-model.c, e-table-selection-model.h, e-table-simple.c, e-table-simple.h, e-table-size-test.c, e-table-sort-info.c, e-table-sort-info.h, e-table-sorted-variable.c, e-table-sorted-variable.h, e-table-sorted.c, e-table-sorted.h, e-table-sorter.c, e-table-sorter.h, e-table-sorting-utils.c, e-table-sorting-utils.h, e-table-specification.c, e-table-specification.h, e-table-state.c, e-table-state.h, e-table-subset-variable.c, e-table-subset-variable.h, e-table-subset.c, e-table-subset.h, e-table-tooltip.h, e-table-tree.h, e-table-utils.c, e-table-utils.h, e-table-without.c, e-table-without.h, e-table.c, e-table.h, e-tree-memory-callbacks.c, e-tree-memory-callbacks.h, e-tree-memory.c, e-tree-memory.h, e-tree-model.c, e-tree-model.h, e-tree-scrolled.c, e-tree-scrolled.h, e-tree-selection-model.c, e-tree-selection-model.h, e-tree-simple.c, e-tree-simple.h, e-tree-sorted-variable.c, e-tree-sorted-variable.h, e-tree-sorted.c, e-tree-sorted.h, e-tree-table-adapter.c, e-tree-table-adapter.h, e-tree.c, e-tree.h, table-test.c, table-test.h, test-check.c, test-cols.c, test-table.c: Changed the license announcement at the top of these files. * e-cell-string.c: Removed unused file. svn path=/trunk/; revision=14154
206 lines
5.6 KiB
C
206 lines
5.6 KiB
C
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
|
/*
|
|
* e-table-extras.c - Set of hash table sort of thingies.
|
|
* Copyright 2000, 2001, Ximian, Inc.
|
|
*
|
|
* Authors:
|
|
* Chris Lahey <clahey@ximian.com>
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Library General Public
|
|
* License, version 2, as published by the Free Software Foundation.
|
|
*
|
|
* This library 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
|
|
* Library General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Library General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
* 02111-1307, USA.
|
|
*/
|
|
|
|
#include <config.h>
|
|
#include <stdlib.h>
|
|
#include <gtk/gtksignal.h>
|
|
#include "gal/util/e-util.h"
|
|
#include "gal/e-table/e-cell-text.h"
|
|
#include "gal/e-table/e-cell-checkbox.h"
|
|
#include "gal/e-table/e-cell-date.h"
|
|
#include "gal/e-table/e-cell-number.h"
|
|
#include "gal/e-table/e-cell-pixbuf.h"
|
|
#include "gal/e-table/e-cell-size.h"
|
|
#include "gal/e-table/e-cell-tree.h"
|
|
#include "e-table-extras.h"
|
|
|
|
#define PARENT_TYPE (gtk_object_get_type())
|
|
|
|
static GtkObjectClass *ete_parent_class;
|
|
|
|
static void
|
|
cell_hash_free(gchar *key,
|
|
ECell *cell,
|
|
gpointer user_data)
|
|
{
|
|
g_free(key);
|
|
if (cell)
|
|
gtk_object_unref( GTK_OBJECT (cell));
|
|
}
|
|
|
|
static void
|
|
pixbuf_hash_free(gchar *key,
|
|
GdkPixbuf *pixbuf,
|
|
gpointer user_data)
|
|
{
|
|
g_free(key);
|
|
if (pixbuf)
|
|
gdk_pixbuf_unref(pixbuf);
|
|
}
|
|
|
|
static void
|
|
ete_destroy (GtkObject *object)
|
|
{
|
|
ETableExtras *ete = E_TABLE_EXTRAS (object);
|
|
|
|
g_hash_table_foreach (ete->cells, (GHFunc) cell_hash_free, NULL);
|
|
g_hash_table_foreach (ete->compares, (GHFunc) g_free, NULL);
|
|
g_hash_table_foreach (ete->pixbufs, (GHFunc) pixbuf_hash_free, NULL);
|
|
|
|
g_hash_table_destroy (ete->cells);
|
|
g_hash_table_destroy (ete->compares);
|
|
g_hash_table_destroy (ete->pixbufs);
|
|
|
|
ete->cells = NULL;
|
|
ete->compares = NULL;
|
|
ete->pixbufs = NULL;
|
|
|
|
GTK_OBJECT_CLASS (ete_parent_class)->destroy (object);
|
|
}
|
|
|
|
static void
|
|
ete_class_init (GtkObjectClass *klass)
|
|
{
|
|
ete_parent_class = gtk_type_class (PARENT_TYPE);
|
|
|
|
klass->destroy = ete_destroy;
|
|
}
|
|
|
|
static gint
|
|
e_strint_compare(gconstpointer data1, gconstpointer data2)
|
|
{
|
|
int int1 = atoi(data1);
|
|
int int2 = atoi(data2);
|
|
|
|
return g_int_compare(GINT_TO_POINTER(int1), GINT_TO_POINTER(int2));
|
|
}
|
|
|
|
static void
|
|
ete_init (ETableExtras *extras)
|
|
{
|
|
extras->cells = g_hash_table_new(g_str_hash, g_str_equal);
|
|
extras->compares = g_hash_table_new(g_str_hash, g_str_equal);
|
|
extras->pixbufs = g_hash_table_new(g_str_hash, g_str_equal);
|
|
|
|
e_table_extras_add_compare(extras, "string", g_str_compare);
|
|
e_table_extras_add_compare(extras, "integer", g_int_compare);
|
|
e_table_extras_add_compare(extras, "string-integer", e_strint_compare);
|
|
|
|
e_table_extras_add_cell(extras, "checkbox", e_cell_checkbox_new());
|
|
e_table_extras_add_cell(extras, "date", e_cell_date_new (NULL, GTK_JUSTIFY_LEFT));
|
|
e_table_extras_add_cell(extras, "number", e_cell_number_new (NULL, GTK_JUSTIFY_RIGHT));
|
|
e_table_extras_add_cell(extras, "pixbuf", e_cell_pixbuf_new ());
|
|
e_table_extras_add_cell(extras, "size", e_cell_size_new (NULL, GTK_JUSTIFY_RIGHT));
|
|
e_table_extras_add_cell(extras, "string", e_cell_text_new (NULL, GTK_JUSTIFY_LEFT));
|
|
e_table_extras_add_cell(extras, "tree-string", e_cell_tree_new (NULL, NULL, TRUE, e_cell_text_new (NULL, GTK_JUSTIFY_LEFT)));
|
|
}
|
|
|
|
E_MAKE_TYPE(e_table_extras, "ETableExtras", ETableExtras, ete_class_init, ete_init, PARENT_TYPE);
|
|
|
|
ETableExtras *
|
|
e_table_extras_new (void)
|
|
{
|
|
ETableExtras *ete = gtk_type_new (E_TABLE_EXTRAS_TYPE);
|
|
|
|
return (ETableExtras *) ete;
|
|
}
|
|
|
|
void
|
|
e_table_extras_add_cell (ETableExtras *extras,
|
|
char *id,
|
|
ECell *cell)
|
|
{
|
|
gchar *old_key;
|
|
ECell *old_cell;
|
|
|
|
if (g_hash_table_lookup_extended (extras->cells, id, (gpointer *)&old_key, (gpointer *)&old_cell)) {
|
|
g_hash_table_remove (extras->cells, old_key);
|
|
g_free (old_key);
|
|
if (old_cell)
|
|
gtk_object_unref (GTK_OBJECT(old_cell));
|
|
}
|
|
|
|
if (cell) {
|
|
gtk_object_ref (GTK_OBJECT (cell));
|
|
gtk_object_sink (GTK_OBJECT (cell));
|
|
}
|
|
g_hash_table_insert (extras->cells, g_strdup(id), cell);
|
|
}
|
|
|
|
ECell *
|
|
e_table_extras_get_cell (ETableExtras *extras,
|
|
char *id)
|
|
{
|
|
return g_hash_table_lookup(extras->cells, id);
|
|
}
|
|
|
|
void
|
|
e_table_extras_add_compare (ETableExtras *extras,
|
|
char *id,
|
|
GCompareFunc compare)
|
|
{
|
|
gchar *old_key;
|
|
GCompareFunc old_compare;
|
|
|
|
if (g_hash_table_lookup_extended (extras->cells, id, (gpointer *)&old_key, (gpointer *)&old_compare)) {
|
|
g_hash_table_remove (extras->cells, old_key);
|
|
g_free (old_key);
|
|
}
|
|
|
|
g_hash_table_insert(extras->compares, g_strdup(id), compare);
|
|
}
|
|
|
|
GCompareFunc
|
|
e_table_extras_get_compare (ETableExtras *extras,
|
|
char *id)
|
|
{
|
|
return g_hash_table_lookup(extras->compares, id);
|
|
}
|
|
|
|
void
|
|
e_table_extras_add_pixbuf (ETableExtras *extras,
|
|
char *id,
|
|
GdkPixbuf *pixbuf)
|
|
{
|
|
gchar *old_key;
|
|
GdkPixbuf *old_pixbuf;
|
|
|
|
if (g_hash_table_lookup_extended (extras->pixbufs, id, (gpointer *)&old_key, (gpointer *)&old_pixbuf)) {
|
|
g_hash_table_remove (extras->cells, old_key);
|
|
g_free (old_key);
|
|
if (old_pixbuf)
|
|
gdk_pixbuf_unref (old_pixbuf);
|
|
}
|
|
|
|
if (pixbuf)
|
|
gdk_pixbuf_ref(pixbuf);
|
|
g_hash_table_insert (extras->pixbufs, g_strdup(id), pixbuf);
|
|
}
|
|
|
|
GdkPixbuf *
|
|
e_table_extras_get_pixbuf (ETableExtras *extras,
|
|
char *id)
|
|
{
|
|
return g_hash_table_lookup(extras->pixbufs, id);
|
|
}
|