Added util/e-sorter-array.lo and widgets/e-reflow-model.lo. Removed
2001-05-07 Christopher James Lahey <clahey@ximian.com> * gal/Makefile.am (libgal_la_LIBADD): Added util/e-sorter-array.lo and widgets/e-reflow-model.lo. Removed widgets/e-reflow-sorted.lo. * gal/util/Makefile.am (libutil_la_SOURCES): Added e-sorter-array.c. (libgalinclude_HEADERS): Added e-sorter-array.h. * gal/util/e-sorter-array.c, gal/util/e-sorter-array.h: A sorter for use with a single compare function to do sorting. * gal/util/e-util.c, gal/util/e-util.h (e_marshal_INT__OBJECT_POINTER): Added this marshaller. * gal/widgets/Makefile.am (libwidgets_la_SOURCES): Added e-reflow-model.c. Removed e-reflow-sorted.c. (libwidgetsinclude_HEADERS): Added e-reflow-sorted.h. Removed e-reflow-model.h. * gal/widgets/e-reflow-model.c, gal/widgets/e-reflow-model.h: Model for EReflow. Has a number of items and generates canvas items on the fly. * gal/widgets/e-reflow.c, gal/widgets/e-reflow.h: Major rewrite. This now uses a model to generate its canvas items instead of having canvas items added to it. It doesn't create the canvas items now until they will be shown on screen. svn path=/trunk/; revision=9710
This commit is contained in:
committed by
Chris Lahey
parent
c1a0dc0e04
commit
5d4895eb43
278
e-util/e-sorter-array.c
Normal file
278
e-util/e-sorter-array.c
Normal file
@ -0,0 +1,278 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
||||
/*
|
||||
* e-sorter-array.c:
|
||||
*
|
||||
* Author:
|
||||
* Christopher James Lahey <clahey@ximian.com>
|
||||
*
|
||||
* (C) 2001 Ximian, Inc.
|
||||
*/
|
||||
#include <config.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <gtk/gtksignal.h>
|
||||
#include "gal/util/e-util.h"
|
||||
#include "e-sorter-array.h"
|
||||
|
||||
#define d(x)
|
||||
|
||||
/* The arguments we take */
|
||||
enum {
|
||||
ARG_0,
|
||||
};
|
||||
|
||||
#define PARENT_TYPE e_sorter_get_type()
|
||||
|
||||
#define INCREMENT_AMOUNT 100
|
||||
|
||||
static ESorterClass *parent_class;
|
||||
|
||||
static void esa_sort (ESorterArray *esa);
|
||||
static void esa_backsort (ESorterArray *esa);
|
||||
|
||||
static gint esa_model_to_sorted (ESorter *sorter, int row);
|
||||
static gint esa_sorted_to_model (ESorter *sorter, int row);
|
||||
static void esa_get_model_to_sorted_array (ESorter *sorter, int **array, int *count);
|
||||
static void esa_get_sorted_to_model_array (ESorter *sorter, int **array, int *count);
|
||||
static gboolean esa_needs_sorting (ESorter *esa);
|
||||
|
||||
#define ESA_NEEDS_SORTING(esa) (((ESorterArray *) (esa))->compare != NULL)
|
||||
|
||||
static int
|
||||
esort_callback(const void *data1, const void *data2, gpointer user_data)
|
||||
{
|
||||
ESorterArray *esa = user_data;
|
||||
int ret_val;
|
||||
int int1, int2;
|
||||
|
||||
int1 = *(int *)data1;
|
||||
int2 = *(int *)data2;
|
||||
|
||||
ret_val = esa->compare (int1, int2, esa->closure);
|
||||
if (ret_val != 0)
|
||||
return ret_val;
|
||||
|
||||
if (int1 < int2)
|
||||
return -1;
|
||||
if (int1 > int2)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
esa_sort(ESorterArray *esa)
|
||||
{
|
||||
int rows;
|
||||
int i;
|
||||
|
||||
if (esa->sorted)
|
||||
return;
|
||||
|
||||
rows = esa->rows;
|
||||
|
||||
esa->sorted = g_new(int, rows);
|
||||
for (i = 0; i < rows; i++)
|
||||
esa->sorted[i] = i;
|
||||
|
||||
if (esa->compare)
|
||||
e_sort (esa->sorted, rows, sizeof(int), esort_callback, esa);
|
||||
}
|
||||
|
||||
static void
|
||||
esa_backsort(ESorterArray *esa)
|
||||
{
|
||||
int i, rows;
|
||||
|
||||
if (esa->backsorted)
|
||||
return;
|
||||
|
||||
esa_sort(esa);
|
||||
|
||||
rows = esa->rows;
|
||||
|
||||
esa->backsorted = g_new0(int, rows);
|
||||
|
||||
for (i = 0; i < rows; i++) {
|
||||
esa->backsorted[esa->sorted[i]] = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static gint
|
||||
esa_model_to_sorted (ESorter *es, int row)
|
||||
{
|
||||
ESorterArray *esa = E_SORTER_ARRAY(es);
|
||||
|
||||
g_return_val_if_fail(row >= 0, -1);
|
||||
g_return_val_if_fail(row < esa->rows, -1);
|
||||
|
||||
if (ESA_NEEDS_SORTING(es))
|
||||
esa_backsort(esa);
|
||||
|
||||
if (esa->backsorted)
|
||||
return esa->backsorted[row];
|
||||
else
|
||||
return row;
|
||||
}
|
||||
|
||||
static gint
|
||||
esa_sorted_to_model (ESorter *es, int row)
|
||||
{
|
||||
ESorterArray *esa = (ESorterArray *) es;
|
||||
|
||||
g_return_val_if_fail(row >= 0, -1);
|
||||
g_return_val_if_fail(row < esa->rows, -1);
|
||||
|
||||
if (ESA_NEEDS_SORTING(es))
|
||||
esa_sort(esa);
|
||||
|
||||
if (esa->sorted)
|
||||
return esa->sorted[row];
|
||||
else
|
||||
return row;
|
||||
}
|
||||
|
||||
static void
|
||||
esa_get_model_to_sorted_array (ESorter *es, int **array, int *count)
|
||||
{
|
||||
ESorterArray *esa = E_SORTER_ARRAY(es);
|
||||
if (array || count) {
|
||||
esa_backsort(esa);
|
||||
|
||||
if (array)
|
||||
*array = esa->backsorted;
|
||||
if (count)
|
||||
*count = esa->rows;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
esa_get_sorted_to_model_array (ESorter *es, int **array, int *count)
|
||||
{
|
||||
ESorterArray *esa = E_SORTER_ARRAY(es);
|
||||
if (array || count) {
|
||||
esa_sort(esa);
|
||||
|
||||
if (array)
|
||||
*array = esa->sorted;
|
||||
if (count)
|
||||
*count = esa->rows;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
esa_needs_sorting(ESorter *es)
|
||||
{
|
||||
ESorterArray *esa = E_SORTER_ARRAY(es);
|
||||
return esa->compare != NULL;
|
||||
}
|
||||
|
||||
void
|
||||
e_sorter_array_clean(ESorterArray *esa)
|
||||
{
|
||||
g_free(esa->sorted);
|
||||
esa->sorted = NULL;
|
||||
|
||||
g_free(esa->backsorted);
|
||||
esa->backsorted = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
e_sorter_array_set_count (ESorterArray *esa, int count)
|
||||
{
|
||||
e_sorter_array_clean (esa);
|
||||
esa->rows = count;
|
||||
}
|
||||
|
||||
void
|
||||
e_sorter_array_append (ESorterArray *esa, int count)
|
||||
{
|
||||
int i;
|
||||
g_free(esa->backsorted);
|
||||
esa->backsorted = NULL;
|
||||
|
||||
if (esa->sorted) {
|
||||
esa->sorted = g_renew(int, esa->sorted, esa->rows + count);
|
||||
for (i = 0; i < count; i++) {
|
||||
int value = esa->rows;
|
||||
int pos;
|
||||
e_bsearch (&value, esa->sorted, esa->rows, sizeof (int), esort_callback, esa, &pos, NULL);
|
||||
memmove (esa->sorted + pos + 1, esa->sorted + pos, sizeof (int) * (esa->rows - pos));
|
||||
esa->sorted[pos] = value;
|
||||
esa->rows ++;
|
||||
}
|
||||
} else {
|
||||
esa->rows = count;
|
||||
}
|
||||
}
|
||||
|
||||
ESorterArray *
|
||||
e_sorter_array_construct (ESorterArray *esa,
|
||||
ECompareRowsFunc compare,
|
||||
gpointer closure)
|
||||
{
|
||||
esa->compare = compare;
|
||||
esa->closure = closure;
|
||||
return esa;
|
||||
}
|
||||
|
||||
ESorterArray *
|
||||
e_sorter_array_new (ECompareRowsFunc compare, gpointer closure)
|
||||
{
|
||||
ESorterArray *esa = gtk_type_new (E_SORTER_ARRAY_TYPE);
|
||||
|
||||
return e_sorter_array_construct (esa, compare, closure);
|
||||
}
|
||||
|
||||
static void
|
||||
esa_destroy (GtkObject *object)
|
||||
{
|
||||
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
||||
}
|
||||
|
||||
static void
|
||||
esa_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
|
||||
{
|
||||
switch (arg_id) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
esa_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
|
||||
{
|
||||
switch (arg_id) {
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
esa_class_init (ESorterArrayClass *klass)
|
||||
{
|
||||
GtkObjectClass *object_class = GTK_OBJECT_CLASS(klass);
|
||||
ESorterClass *sorter_class = E_SORTER_CLASS(klass);
|
||||
|
||||
parent_class = gtk_type_class (PARENT_TYPE);
|
||||
|
||||
object_class->destroy = esa_destroy;
|
||||
object_class->set_arg = esa_set_arg;
|
||||
object_class->get_arg = esa_get_arg;
|
||||
|
||||
sorter_class->model_to_sorted = esa_model_to_sorted ;
|
||||
sorter_class->sorted_to_model = esa_sorted_to_model ;
|
||||
sorter_class->get_model_to_sorted_array = esa_get_model_to_sorted_array ;
|
||||
sorter_class->get_sorted_to_model_array = esa_get_sorted_to_model_array ;
|
||||
sorter_class->needs_sorting = esa_needs_sorting ;
|
||||
}
|
||||
|
||||
static void
|
||||
esa_init (ESorterArray *esa)
|
||||
{
|
||||
esa->rows = 0;
|
||||
esa->compare = NULL;
|
||||
esa->closure = NULL;
|
||||
esa->sorted = NULL;
|
||||
esa->backsorted = NULL;
|
||||
}
|
||||
|
||||
E_MAKE_TYPE(e_sorter_array, "ESorterArray", ESorterArray, esa_class_init, esa_init, PARENT_TYPE);
|
||||
56
e-util/e-sorter-array.h
Normal file
56
e-util/e-sorter-array.h
Normal file
@ -0,0 +1,56 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
||||
#ifndef _E_SORTER_ARRAY_H_
|
||||
#define _E_SORTER_ARRAY_H_
|
||||
|
||||
#include <gtk/gtkobject.h>
|
||||
#include <gal/util/e-sorter.h>
|
||||
#include <glib.h>
|
||||
#include <libgnome/gnome-defs.h>
|
||||
|
||||
BEGIN_GNOME_DECLS
|
||||
|
||||
#define E_SORTER_ARRAY_TYPE (e_sorter_array_get_type ())
|
||||
#define E_SORTER_ARRAY(o) (GTK_CHECK_CAST ((o), E_SORTER_ARRAY_TYPE, ESorterArray))
|
||||
#define E_SORTER_ARRAY_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_SORTER_ARRAY_TYPE, ESorterArrayClass))
|
||||
#define E_IS_SORTER_ARRAY(o) (GTK_CHECK_TYPE ((o), E_SORTER_ARRAY_TYPE))
|
||||
#define E_IS_SORTER_ARRAY_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_SORTER_ARRAY_TYPE))
|
||||
|
||||
#ifndef _E_COMPARE_ROWS_FUNC_H_
|
||||
#define _E_COMPARE_ROWS_FUNC_H_
|
||||
typedef int (*ECompareRowsFunc) (int row1,
|
||||
int row2,
|
||||
gpointer closure);
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
ESorter base;
|
||||
|
||||
ECompareRowsFunc compare;
|
||||
gpointer closure;
|
||||
|
||||
/* If needs_sorting is 0, then model_to_sorted and sorted_to_model are no-ops. */
|
||||
int *sorted;
|
||||
int *backsorted;
|
||||
|
||||
int rows;
|
||||
} ESorterArray;
|
||||
|
||||
typedef struct {
|
||||
ESorterClass parent_class;
|
||||
} ESorterArrayClass;
|
||||
|
||||
GtkType e_sorter_array_get_type (void);
|
||||
ESorterArray *e_sorter_array_construct (ESorterArray *sorter,
|
||||
ECompareRowsFunc compare,
|
||||
gpointer closure);
|
||||
ESorterArray *e_sorter_array_new (ECompareRowsFunc compare,
|
||||
gpointer closure);
|
||||
void e_sorter_array_clean (ESorterArray *esa);
|
||||
void e_sorter_array_set_count (ESorterArray *esa,
|
||||
int count);
|
||||
void e_sorter_array_append (ESorterArray *esa,
|
||||
int count);
|
||||
|
||||
END_GNOME_DECLS
|
||||
|
||||
#endif /* _E_SORTER_ARRAY_H_ */
|
||||
@ -678,6 +678,27 @@ e_marshal_NONE__POINTER_INT_INT_INT (GtkObject *object,
|
||||
func_data);
|
||||
}
|
||||
|
||||
typedef int (*GtkSignal_INT__OBJECT_POINTER) (GtkObject *,
|
||||
GtkObject *, gpointer,
|
||||
gpointer user_data);
|
||||
void
|
||||
e_marshal_INT__OBJECT_POINTER (GtkObject *object,
|
||||
GtkSignalFunc func,
|
||||
gpointer func_data,
|
||||
GtkArg *args)
|
||||
{
|
||||
GtkSignal_INT__OBJECT_POINTER rfunc;
|
||||
int *return_val;
|
||||
|
||||
rfunc = (GtkSignal_INT__OBJECT_POINTER) func;
|
||||
return_val = GTK_RETLOC_INT (args[2]);
|
||||
|
||||
*return_val = (*rfunc) (object,
|
||||
GTK_VALUE_OBJECT (args[0]),
|
||||
GTK_VALUE_POINTER (args[1]),
|
||||
func_data);
|
||||
}
|
||||
|
||||
gchar**
|
||||
e_strsplit (const gchar *string,
|
||||
const gchar *delimiter,
|
||||
|
||||
@ -80,14 +80,12 @@ gchar *e_strstrcase (cons
|
||||
void e_filename_make_safe (gchar *string);
|
||||
gchar *e_format_number (gint number);
|
||||
gchar *e_format_number_float (gfloat number);
|
||||
|
||||
gboolean e_create_directory (gchar *directory);
|
||||
|
||||
|
||||
typedef int (*ESortCompareFunc) (const void *first,
|
||||
const void *second,
|
||||
gpointer closure);
|
||||
|
||||
void e_sort (void *base,
|
||||
size_t nmemb,
|
||||
size_t size,
|
||||
@ -99,11 +97,8 @@ void e_bsearch (cons
|
||||
size_t size,
|
||||
ESortCompareFunc compare,
|
||||
gpointer closure,
|
||||
size_t *start,
|
||||
size_t *end);
|
||||
|
||||
|
||||
|
||||
size_t *start,
|
||||
size_t *end);
|
||||
void e_marshal_INT__INT_INT_POINTER (GtkObject *object,
|
||||
GtkSignalFunc func,
|
||||
gpointer func_data,
|
||||
@ -192,11 +187,15 @@ void e_marshal_INT__POINTER_POINTER_POINTER_POINTER (GtkO
|
||||
GtkSignalFunc func,
|
||||
gpointer func_data,
|
||||
GtkArg *args);
|
||||
void e_marshal_NONE__POINTER_INT_INT_INT (GtkObject *object,
|
||||
GtkSignalFunc func,
|
||||
gpointer func_data,
|
||||
GtkArg *args);
|
||||
void e_marshal_INT__OBJECT_POINTER (GtkObject *object,
|
||||
GtkSignalFunc func,
|
||||
gpointer func_data,
|
||||
GtkArg *args);
|
||||
|
||||
void e_marshal_NONE__POINTER_INT_INT_INT (GtkObject *object,
|
||||
GtkSignalFunc func,
|
||||
gpointer func_data,
|
||||
GtkArg *args);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
288
widgets/misc/e-reflow-model.c
Normal file
288
widgets/misc/e-reflow-model.c
Normal file
@ -0,0 +1,288 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
||||
/*
|
||||
* e-reflow-model.c: a Reflow Model
|
||||
*
|
||||
* Authors:
|
||||
* Chris Lahey <clahey@ximian.com>
|
||||
*
|
||||
* (C) 2001 Ximian, Inc.
|
||||
*/
|
||||
#include <config.h>
|
||||
#include "e-reflow-model.h"
|
||||
#include <gtk/gtksignal.h>
|
||||
|
||||
#define ERM_CLASS(e) ((EReflowModelClass *)((GtkObject *)e)->klass)
|
||||
|
||||
#define PARENT_TYPE gtk_object_get_type ()
|
||||
|
||||
#define d(x)
|
||||
|
||||
d(static gint depth = 0);
|
||||
|
||||
|
||||
static GtkObjectClass *e_reflow_model_parent_class;
|
||||
|
||||
enum {
|
||||
MODEL_CHANGED,
|
||||
MODEL_ITEMS_INSERTED,
|
||||
MODEL_ITEM_CHANGED,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint e_reflow_model_signals [LAST_SIGNAL] = { 0, };
|
||||
|
||||
/**
|
||||
* e_reflow_model_set_width:
|
||||
* @e_reflow_model: The e-reflow-model to operate on
|
||||
* @width: The new value for the width of each item.
|
||||
*/
|
||||
void
|
||||
e_reflow_model_set_width (EReflowModel *e_reflow_model, int width)
|
||||
{
|
||||
g_return_if_fail (e_reflow_model != NULL);
|
||||
g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model));
|
||||
|
||||
ERM_CLASS (e_reflow_model)->set_width (e_reflow_model, width);
|
||||
}
|
||||
|
||||
/**
|
||||
* e_reflow_model_count:
|
||||
* @e_reflow_model: The e-reflow-model to operate on
|
||||
*
|
||||
* Returns: the number of items in the reflow model.
|
||||
*/
|
||||
int
|
||||
e_reflow_model_count (EReflowModel *e_reflow_model)
|
||||
{
|
||||
g_return_val_if_fail (e_reflow_model != NULL, 0);
|
||||
g_return_val_if_fail (E_IS_REFLOW_MODEL (e_reflow_model), 0);
|
||||
|
||||
return ERM_CLASS (e_reflow_model)->count (e_reflow_model);
|
||||
}
|
||||
|
||||
/**
|
||||
* e_reflow_model_height:
|
||||
* @e_reflow_model: The e-reflow-model to operate on
|
||||
* @n: The item number to get the height of.
|
||||
* @parent: The parent GnomeCanvasItem.
|
||||
*
|
||||
* Returns: the height of the nth item.
|
||||
*/
|
||||
int
|
||||
e_reflow_model_height (EReflowModel *e_reflow_model, int n, GnomeCanvasGroup *parent)
|
||||
{
|
||||
g_return_val_if_fail (e_reflow_model != NULL, 0);
|
||||
g_return_val_if_fail (E_IS_REFLOW_MODEL (e_reflow_model), 0);
|
||||
|
||||
return ERM_CLASS (e_reflow_model)->height (e_reflow_model, n, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* e_reflow_model_incarnate:
|
||||
* @e_reflow_model: The e-reflow-model to operate on
|
||||
* @n: The item to create.
|
||||
* @parent: The parent GnomeCanvasItem to create a child of.
|
||||
*
|
||||
* Create a GnomeCanvasItem to represent the nth piece of data.
|
||||
*
|
||||
* Returns: the new GnomeCanvasItem.
|
||||
*/
|
||||
GnomeCanvasItem *
|
||||
e_reflow_model_incarnate (EReflowModel *e_reflow_model, int n, GnomeCanvasGroup *parent)
|
||||
{
|
||||
g_return_val_if_fail (e_reflow_model != NULL, NULL);
|
||||
g_return_val_if_fail (E_IS_REFLOW_MODEL (e_reflow_model), NULL);
|
||||
|
||||
return ERM_CLASS (e_reflow_model)->incarnate (e_reflow_model, n, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* e_reflow_model_compare:
|
||||
* @e_reflow_model: The e-reflow-model to operate on
|
||||
* @n1: The first item to compare
|
||||
* @n2: The second item to compare
|
||||
*
|
||||
* Compares item n1 and item n2 to see which should come first.
|
||||
*
|
||||
* Returns: strcmp like semantics for the comparison value.
|
||||
*/
|
||||
int
|
||||
e_reflow_model_compare (EReflowModel *e_reflow_model, int n1, int n2)
|
||||
{
|
||||
#if 0
|
||||
g_return_val_if_fail (e_reflow_model != NULL, 0);
|
||||
g_return_val_if_fail (E_IS_REFLOW_MODEL (e_reflow_model), 0);
|
||||
#endif
|
||||
|
||||
return ERM_CLASS (e_reflow_model)->compare (e_reflow_model, n1, n2);
|
||||
}
|
||||
|
||||
/**
|
||||
* e_reflow_model_reincarnate:
|
||||
* @e_reflow_model: The e-reflow-model to operate on
|
||||
* @n: The item to create.
|
||||
* @item: The item to reuse.
|
||||
*
|
||||
* Update item to represent the nth piece of data.
|
||||
*/
|
||||
void
|
||||
e_reflow_model_reincarnate (EReflowModel *e_reflow_model, int n, GnomeCanvasItem *item)
|
||||
{
|
||||
g_return_if_fail (e_reflow_model != NULL);
|
||||
g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model));
|
||||
|
||||
ERM_CLASS (e_reflow_model)->reincarnate (e_reflow_model, n, item);
|
||||
}
|
||||
|
||||
static void
|
||||
e_reflow_model_class_init (GtkObjectClass *object_class)
|
||||
{
|
||||
EReflowModelClass *klass = E_REFLOW_MODEL_CLASS(object_class);
|
||||
e_reflow_model_parent_class = gtk_type_class (PARENT_TYPE);
|
||||
|
||||
e_reflow_model_signals [MODEL_CHANGED] =
|
||||
gtk_signal_new ("model_changed",
|
||||
GTK_RUN_LAST,
|
||||
object_class->type,
|
||||
GTK_SIGNAL_OFFSET (EReflowModelClass, model_changed),
|
||||
gtk_marshal_NONE__NONE,
|
||||
GTK_TYPE_NONE, 0);
|
||||
|
||||
e_reflow_model_signals [MODEL_ITEMS_INSERTED] =
|
||||
gtk_signal_new ("model_items_inserted",
|
||||
GTK_RUN_LAST,
|
||||
object_class->type,
|
||||
GTK_SIGNAL_OFFSET (EReflowModelClass, model_items_inserted),
|
||||
gtk_marshal_NONE__INT_INT,
|
||||
GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT);
|
||||
|
||||
e_reflow_model_signals [MODEL_ITEM_CHANGED] =
|
||||
gtk_signal_new ("model_item_changed",
|
||||
GTK_RUN_LAST,
|
||||
object_class->type,
|
||||
GTK_SIGNAL_OFFSET (EReflowModelClass, model_item_changed),
|
||||
gtk_marshal_NONE__INT,
|
||||
GTK_TYPE_NONE, 1, GTK_TYPE_INT);
|
||||
|
||||
gtk_object_class_add_signals (object_class, e_reflow_model_signals, LAST_SIGNAL);
|
||||
|
||||
klass->set_width = NULL;
|
||||
klass->count = NULL;
|
||||
klass->height = NULL;
|
||||
klass->incarnate = NULL;
|
||||
klass->reincarnate = NULL;
|
||||
|
||||
klass->model_changed = NULL;
|
||||
klass->model_items_inserted = NULL;
|
||||
klass->model_item_changed = NULL;
|
||||
}
|
||||
|
||||
|
||||
guint
|
||||
e_reflow_model_get_type (void)
|
||||
{
|
||||
static guint type = 0;
|
||||
|
||||
if (!type)
|
||||
{
|
||||
GtkTypeInfo info =
|
||||
{
|
||||
"EReflowModel",
|
||||
sizeof (EReflowModel),
|
||||
sizeof (EReflowModelClass),
|
||||
(GtkClassInitFunc) e_reflow_model_class_init,
|
||||
NULL,
|
||||
/* reserved_1 */ NULL,
|
||||
/* reserved_2 */ NULL,
|
||||
(GtkClassInitFunc) NULL,
|
||||
};
|
||||
|
||||
type = gtk_type_unique (PARENT_TYPE, &info);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
#if d(!)0
|
||||
static void
|
||||
print_tabs (void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < depth; i++)
|
||||
g_print("\t");
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* e_reflow_model_changed:
|
||||
* @e_reflow_model: the reflow model to notify of the change
|
||||
*
|
||||
* Use this function to notify any views of this reflow model that
|
||||
* the contents of the reflow model have changed. This will emit
|
||||
* the signal "model_changed" on the @e_reflow_model object.
|
||||
*
|
||||
* It is preferable to use the e_reflow_model_item_changed() signal to
|
||||
* notify of smaller changes than to invalidate the entire model, as
|
||||
* the views might have ways of caching the information they render
|
||||
* from the model.
|
||||
*/
|
||||
void
|
||||
e_reflow_model_changed (EReflowModel *e_reflow_model)
|
||||
{
|
||||
g_return_if_fail (e_reflow_model != NULL);
|
||||
g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model));
|
||||
|
||||
d(print_tabs());
|
||||
d(g_print("Emitting model_changed on model 0x%p.\n", e_reflow_model));
|
||||
d(depth++);
|
||||
gtk_signal_emit (GTK_OBJECT (e_reflow_model),
|
||||
e_reflow_model_signals [MODEL_CHANGED]);
|
||||
d(depth--);
|
||||
}
|
||||
|
||||
/**
|
||||
* e_reflow_model_items_inserted:
|
||||
* @e_reflow_model: The model changed.
|
||||
* @position: The position the items were insert in.
|
||||
* @count: The number of items inserted.
|
||||
*
|
||||
* Use this function to notify any views of the reflow model that a number of items have been inserted.
|
||||
**/
|
||||
void
|
||||
e_reflow_model_items_inserted (EReflowModel *e_reflow_model, int position, int count)
|
||||
{
|
||||
g_return_if_fail (e_reflow_model != NULL);
|
||||
g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model));
|
||||
|
||||
d(print_tabs());
|
||||
d(g_print("Emitting items_inserted on model 0x%p, position=%d, count=%d.\n", e_reflow_model, position, count));
|
||||
d(depth++);
|
||||
gtk_signal_emit (GTK_OBJECT (e_reflow_model),
|
||||
e_reflow_model_signals [MODEL_ITEMS_INSERTED], position, count);
|
||||
d(depth--);
|
||||
}
|
||||
|
||||
/**
|
||||
* e_reflow_model_item_changed:
|
||||
* @e_reflow_model: the reflow model to notify of the change
|
||||
* @item: the item that was changed in the model.
|
||||
*
|
||||
* Use this function to notify any views of the reflow model that the
|
||||
* contents of item @item have changed in model such that the height
|
||||
* has changed or the item needs to be reincarnated. This function
|
||||
* will emit the "model_item_changed" signal on the @e_reflow_model
|
||||
* object
|
||||
*/
|
||||
void
|
||||
e_reflow_model_item_changed (EReflowModel *e_reflow_model, int n)
|
||||
{
|
||||
g_return_if_fail (e_reflow_model != NULL);
|
||||
g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model));
|
||||
|
||||
d(print_tabs());
|
||||
d(g_print("Emitting item_changed on model 0x%p, n=%d.\n", e_reflow_model, n));
|
||||
d(depth++);
|
||||
gtk_signal_emit (GTK_OBJECT (e_reflow_model),
|
||||
e_reflow_model_signals [MODEL_ITEM_CHANGED], n);
|
||||
d(depth--);
|
||||
}
|
||||
83
widgets/misc/e-reflow-model.h
Normal file
83
widgets/misc/e-reflow-model.h
Normal file
@ -0,0 +1,83 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
||||
#ifndef _E_REFLOW_MODEL_H_
|
||||
#define _E_REFLOW_MODEL_H_
|
||||
|
||||
#include <gtk/gtkobject.h>
|
||||
#include <libgnomeui/gnome-canvas.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define E_REFLOW_MODEL_TYPE (e_reflow_model_get_type ())
|
||||
#define E_REFLOW_MODEL(o) (GTK_CHECK_CAST ((o), E_REFLOW_MODEL_TYPE, EReflowModel))
|
||||
#define E_REFLOW_MODEL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_REFLOW_MODEL_TYPE, EReflowModelClass))
|
||||
#define E_IS_REFLOW_MODEL(o) (GTK_CHECK_TYPE ((o), E_REFLOW_MODEL_TYPE))
|
||||
#define E_IS_REFLOW_MODEL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_REFLOW_MODEL_TYPE))
|
||||
|
||||
typedef struct {
|
||||
GtkObject base;
|
||||
} EReflowModel;
|
||||
|
||||
typedef struct {
|
||||
GtkObjectClass parent_class;
|
||||
|
||||
/*
|
||||
* Virtual methods
|
||||
*/
|
||||
void (*set_width) (EReflowModel *etm, int width);
|
||||
|
||||
int (*count) (EReflowModel *etm);
|
||||
int (*height) (EReflowModel *etm, int n, GnomeCanvasGroup *parent);
|
||||
GnomeCanvasItem *(*incarnate) (EReflowModel *etm, int n, GnomeCanvasGroup *parent);
|
||||
int (*compare) (EReflowModel *etm, int n1, int n2);
|
||||
void (*reincarnate) (EReflowModel *etm, int n, GnomeCanvasItem *item);
|
||||
|
||||
/*
|
||||
* Signals
|
||||
*/
|
||||
|
||||
/*
|
||||
* These all come after the change has been made.
|
||||
* Major structural changes: model_changed
|
||||
* Changes only in an item: item_changed
|
||||
*/
|
||||
void (*model_changed) (EReflowModel *etm);
|
||||
void (*model_items_inserted) (EReflowModel *etm, int position, int count);
|
||||
void (*model_item_changed) (EReflowModel *etm, int n);
|
||||
} EReflowModelClass;
|
||||
|
||||
GtkType e_reflow_model_get_type (void);
|
||||
|
||||
/**/
|
||||
void e_reflow_model_set_width (EReflowModel *e_reflow_model,
|
||||
int width);
|
||||
int e_reflow_model_count (EReflowModel *e_reflow_model);
|
||||
int e_reflow_model_height (EReflowModel *e_reflow_model,
|
||||
int n,
|
||||
GnomeCanvasGroup *parent);
|
||||
GnomeCanvasItem *e_reflow_model_incarnate (EReflowModel *e_reflow_model,
|
||||
int n,
|
||||
GnomeCanvasGroup *parent);
|
||||
int e_reflow_model_compare (EReflowModel *e_reflow_model,
|
||||
int n1,
|
||||
int n2);
|
||||
void e_reflow_model_reincarnate (EReflowModel *e_reflow_model,
|
||||
int n,
|
||||
GnomeCanvasItem *item);
|
||||
|
||||
/*
|
||||
* Routines for emitting signals on the e_reflow
|
||||
*/
|
||||
void e_reflow_model_changed (EReflowModel *e_reflow_model);
|
||||
void e_reflow_model_items_inserted (EReflowModel *e_reflow_model,
|
||||
int position,
|
||||
int count);
|
||||
void e_reflow_model_item_changed (EReflowModel *e_reflow_model,
|
||||
int n);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _E_REFLOW_MODEL_H_ */
|
||||
File diff suppressed because it is too large
Load Diff
@ -22,6 +22,9 @@
|
||||
#define __E_REFLOW_H__
|
||||
|
||||
#include <libgnomeui/gnome-canvas.h>
|
||||
#include <gal/widgets/e-reflow-model.h>
|
||||
#include <gal/widgets/e-selection-model.h>
|
||||
#include <gal/util/e-sorter-array.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -46,6 +49,8 @@ extern "C" {
|
||||
#define E_IS_REFLOW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_REFLOW_TYPE))
|
||||
|
||||
|
||||
typedef struct EReflowPriv EReflowPriv;
|
||||
|
||||
typedef struct _EReflow EReflow;
|
||||
typedef struct _EReflowClass EReflowClass;
|
||||
|
||||
@ -54,30 +59,50 @@ struct _EReflow
|
||||
GnomeCanvasGroup parent;
|
||||
|
||||
/* item specific fields */
|
||||
GList *items; /* Of type GnomeCanvasItem */
|
||||
GList *columns; /* Of type GList of type GnomeCanvasItem (points into items) */
|
||||
EReflowModel *model;
|
||||
guint model_changed_id;
|
||||
guint model_items_inserted_id;
|
||||
guint model_item_changed_id;
|
||||
|
||||
ESelectionModel *selection;
|
||||
guint selection_changed_id;
|
||||
ESorterArray *sorter;
|
||||
|
||||
GtkAdjustment *adjustment;
|
||||
guint adjustment_changed_id;
|
||||
guint adjustment_value_changed_id;
|
||||
guint set_scroll_adjustments_id;
|
||||
|
||||
int *heights;
|
||||
GnomeCanvasItem **items;
|
||||
int count;
|
||||
int allocated_count;
|
||||
|
||||
int *columns;
|
||||
gint column_count; /* Number of columnns */
|
||||
|
||||
GnomeCanvasItem *empty_text;
|
||||
gchar *empty_message;
|
||||
|
||||
|
||||
double minimum_width;
|
||||
double width;
|
||||
double height;
|
||||
|
||||
|
||||
double column_width;
|
||||
|
||||
int idle;
|
||||
int incarnate_idle_id;
|
||||
|
||||
/* These are all for when the column is being dragged. */
|
||||
gboolean column_drag;
|
||||
gdouble start_x;
|
||||
gint which_column_dragged;
|
||||
double temp_column_width;
|
||||
double previous_temp_column_width;
|
||||
|
||||
guint column_drag : 1;
|
||||
|
||||
guint need_height_update : 1;
|
||||
guint need_column_resize : 1;
|
||||
guint need_reflow_columns : 1;
|
||||
|
||||
guint default_cursor_shown : 1;
|
||||
GdkCursor *arrow_cursor;
|
||||
@ -88,8 +113,7 @@ struct _EReflowClass
|
||||
{
|
||||
GnomeCanvasGroupClass parent_class;
|
||||
|
||||
/* Virtual methods. */
|
||||
void (* add_item) (EReflow *reflow, GnomeCanvasItem *item, gint *position);
|
||||
int (*selection_event) (EReflow *reflow, GnomeCanvasItem *item, GdkEvent *event);
|
||||
};
|
||||
|
||||
/*
|
||||
@ -98,18 +122,10 @@ struct _EReflowClass
|
||||
* should also do an ECanvas parent reflow request if its size
|
||||
* changes.
|
||||
*/
|
||||
void e_reflow_add_item (EReflow *e_reflow,
|
||||
GnomeCanvasItem *item,
|
||||
gint *position);
|
||||
GtkType e_reflow_get_type (void);
|
||||
|
||||
/* Internal usage only: */
|
||||
void e_reflow_post_add_item (EReflow *e_reflow,
|
||||
GnomeCanvasItem *item);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#endif /* __E_REFLOW_H__ */
|
||||
|
||||
Reference in New Issue
Block a user