Files
evolution/widgets/table/e-table-scrolled.c
Christopher James Lahey e16e25daa7 Changed these to match the new ETable system.
2000-10-11  Christopher James Lahey  <clahey@helixcode.com>

	* tests/test-tree-1.c, tests/test-tree-2.c, tests/test-tree-3.c:
	Changed these to match the new ETable system.

	* gal/Makefile.am: Added e-table-column-specification.lo,
	e-table-extras.lo, e-table-specification.lo, and e-table-state.lo.

From gal/e-table/ChangeLog:

2000-10-11  Christopher James Lahey  <clahey@helixcode.com>

	* Makefile.am: Added e-table-column-specification.c,
	e-table-column-specification.h, e-table-extras.c,
	e-table-extras.h, e-table-specification.c,
	e-table-specification.h, e-table-state.c, and e-table-state.h.
	Removed some duplicated .h files.

	* e-cell-tree.c: Ref, sink, and unref the subcell instead of destroying
	it when done.

	* e-table-column-specification.c, e-table-column-specification.h:
	New class which describes a column without having a table get
	instantiated.

	* e-table-config.c: Changed get_specification to get_state to get
	this to compile.

	* e-table-defines.h, e-table-item.h: Moved the definition of
	ETableCursorMode from e-table-item.h to e-table-defines.h.

	* e-table-extras.c, e-table-extras.h: New class which acts as a
	set of 3 hash tables.  All from char * and to alternately, ECells,
	GCompareFuncs, and GdkPxibufs.

	* e-table-scrolled.c, e-table-scrolled.h: Changed this to match
	the new ETable function declarations.

	* e-table-sort-info.c, e-table-sort-info.h: Added functions for
	saving to and loading from xml.

	* e-table-specification.c, e-table-specification.h: New class
	which describes a table without having to instantiate it.

	* e-table-state.c, e-table-state.h: New class which describes the
	state of a table without having to instantiate the table.

	* e-table.c, e-table.h: Changed this to accept both a state and a
	specification instead of just a specification.  You then save only
	the state.  The specification stays exactly the same.  Also, you
	no longer need to pass in an ETableHeader.  Most of the
	information contained in the ETableHeader are in the
	specification.  However you may need to translate some of the
	strings in the specification to objects.  If you need anything
	other than the builtin choices, you need to create an ETableExtras
	and pass it in.

	* e-tree-model.c: Removed an unused variable.

svn path=/trunk/; revision=5837
2000-10-11 08:16:37 +00:00

412 lines
11 KiB
C

/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* E-table-scrolled.c: A graphical view of a Table.
*
* Author:
* Chris Lahey <clahey@helixcode.com>
* Miguel de Icaza (miguel@helixcode.com)
*
* Copyright 2000, 1999, Helix Code, Inc
*/
#include <config.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <libgnomeui/gnome-canvas.h>
#include <gtk/gtksignal.h>
#include <gnome-xml/parser.h>
#include <gnome-xml/xmlmemory.h>
#include "e-table.h"
#include "e-table-scrolled.h"
#define COLUMN_HEADER_HEIGHT 16
#define PARENT_TYPE e_scroll_frame_get_type ()
static GtkObjectClass *parent_class;
enum {
CURSOR_CHANGE,
DOUBLE_CLICK,
RIGHT_CLICK,
KEY_PRESS,
LAST_SIGNAL
};
enum {
ARG_0,
ARG_TABLE_DRAW_GRID,
ARG_TABLE_DRAW_FOCUS,
ARG_CURSOR_MODE,
ARG_LENGTH_THRESHOLD,
ARG_CLICK_TO_ADD_MESSAGE,
};
static gint ets_signals [LAST_SIGNAL] = { 0, };
static void
cursor_change_proxy (ETable *et, int row, ETableScrolled *ets)
{
gtk_signal_emit (GTK_OBJECT (ets),
ets_signals [CURSOR_CHANGE],
row);
}
static void
double_click_proxy (ETable *et, int row, ETableScrolled *ets)
{
gtk_signal_emit (GTK_OBJECT (ets),
ets_signals [DOUBLE_CLICK],
row);
}
static gint
right_click_proxy (ETable *et, int row, int col, GdkEvent *event, ETableScrolled *ets)
{
int return_val = 0;
gtk_signal_emit (GTK_OBJECT (ets),
ets_signals [RIGHT_CLICK],
row, col, event, &return_val);
return return_val;
}
static gint
key_press_proxy (ETable *et, int row, int col, GdkEvent *event, ETableScrolled *ets)
{
int return_val;
gtk_signal_emit (GTK_OBJECT (ets),
ets_signals [KEY_PRESS],
row, col, event, &return_val);
return return_val;
}
static void
e_table_scrolled_init (GtkObject *object)
{
ETableScrolled *ets;
EScrollFrame *scroll_frame;
ets = E_TABLE_SCROLLED (object);
scroll_frame = E_SCROLL_FRAME (object);
ets->table = gtk_type_new(e_table_get_type());
e_scroll_frame_set_policy (scroll_frame, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
e_scroll_frame_set_shadow_type (scroll_frame, GTK_SHADOW_IN);
}
static void
e_table_scrolled_real_construct (ETableScrolled *ets)
{
gtk_object_set(GTK_OBJECT(ets),
"shadow_type", GTK_SHADOW_IN,
"hscrollbar_policy", GTK_POLICY_NEVER,
"vscrollbar_policy", GTK_POLICY_AUTOMATIC,
NULL);
gtk_container_add(GTK_CONTAINER(ets), GTK_WIDGET(ets->table));
gtk_signal_connect(GTK_OBJECT(ets->table), "cursor_change",
GTK_SIGNAL_FUNC(cursor_change_proxy), ets);
gtk_signal_connect(GTK_OBJECT(ets->table), "double_click",
GTK_SIGNAL_FUNC(double_click_proxy), ets);
gtk_signal_connect(GTK_OBJECT(ets->table), "right_click",
GTK_SIGNAL_FUNC(right_click_proxy), ets);
gtk_signal_connect(GTK_OBJECT(ets->table), "key_press",
GTK_SIGNAL_FUNC(key_press_proxy), ets);
gtk_widget_show(GTK_WIDGET(ets->table));
}
ETableScrolled *e_table_scrolled_construct (ETableScrolled *ets,
ETableModel *etm,
ETableExtras *ete,
const char *spec,
const char *state)
{
g_return_val_if_fail(ets != NULL, NULL);
g_return_val_if_fail(E_IS_TABLE_SCROLLED(ets), NULL);
g_return_val_if_fail(etm != NULL, NULL);
g_return_val_if_fail(E_IS_TABLE_MODEL(etm), NULL);
g_return_val_if_fail(ete == NULL || E_IS_TABLE_EXTRAS(ete), NULL);
g_return_val_if_fail(spec != NULL, NULL);
e_table_construct(ets->table, etm, ete, spec, state);
e_table_scrolled_real_construct(ets);
return ets;
}
GtkWidget *e_table_scrolled_new (ETableModel *etm,
ETableExtras *ete,
const char *spec,
const char *state)
{
ETableScrolled *ets;
g_return_val_if_fail(etm != NULL, NULL);
g_return_val_if_fail(E_IS_TABLE_MODEL(etm), NULL);
g_return_val_if_fail(ete == NULL || E_IS_TABLE_EXTRAS(ete), NULL);
g_return_val_if_fail(spec != NULL, NULL);
ets = E_TABLE_SCROLLED (gtk_widget_new (e_table_scrolled_get_type (),
"hadjustment", NULL,
"vadjustment", NULL,
NULL));
ets = e_table_scrolled_construct (ets, etm, ete, spec, state);
return GTK_WIDGET (ets);
}
ETableScrolled *e_table_scrolled_construct_from_spec_file (ETableScrolled *ets,
ETableModel *etm,
ETableExtras *ete,
const char *spec_fn,
const char *state_fn)
{
g_return_val_if_fail(ets != NULL, NULL);
g_return_val_if_fail(E_IS_TABLE_SCROLLED(ets), NULL);
g_return_val_if_fail(etm != NULL, NULL);
g_return_val_if_fail(E_IS_TABLE_MODEL(etm), NULL);
g_return_val_if_fail(ete == NULL || E_IS_TABLE_EXTRAS(ete), NULL);
g_return_val_if_fail(spec_fn != NULL, NULL);
e_table_construct_from_spec_file(ets->table, etm, ete, spec_fn, state_fn);
e_table_scrolled_real_construct(ets);
return ets;
}
GtkWidget *e_table_scrolled_new_from_spec_file (ETableModel *etm,
ETableExtras *ete,
const char *spec_fn,
const char *state_fn)
{
ETableScrolled *ets;
g_return_val_if_fail(etm != NULL, NULL);
g_return_val_if_fail(E_IS_TABLE_MODEL(etm), NULL);
g_return_val_if_fail(ete == NULL || E_IS_TABLE_EXTRAS(ete), NULL);
g_return_val_if_fail(spec_fn != NULL, NULL);
ets = gtk_type_new (e_table_scrolled_get_type ());
ets = e_table_scrolled_construct_from_spec_file (ets, etm, ete, spec_fn, state_fn);
return GTK_WIDGET (ets);
}
gchar *e_table_scrolled_get_state (ETableScrolled *ets)
{
g_return_val_if_fail(ets != NULL, NULL);
g_return_val_if_fail(E_IS_TABLE_SCROLLED(ets), NULL);
return e_table_get_state(ets->table);
}
void e_table_scrolled_save_state (ETableScrolled *ets,
const gchar *filename)
{
g_return_if_fail(ets != NULL);
g_return_if_fail(E_IS_TABLE_SCROLLED(ets));
g_return_if_fail(filename != NULL);
e_table_save_state(ets->table, filename);
}
void
e_table_scrolled_set_state(ETableScrolled *ets, const char *state)
{
g_return_if_fail(ets != NULL);
g_return_if_fail(E_IS_TABLE_SCROLLED(ets));
g_return_if_fail(state != NULL);
e_table_set_state(ets->table, state);
}
void
e_table_scrolled_load_state(ETableScrolled *ets, const gchar *filename)
{
g_return_if_fail(ets != NULL);
g_return_if_fail(E_IS_TABLE_SCROLLED(ets));
g_return_if_fail(filename != NULL);
e_table_load_state(ets->table, filename);
}
void
e_table_scrolled_set_cursor_row (ETableScrolled *ets, int row)
{
g_return_if_fail(ets != NULL);
g_return_if_fail(E_IS_TABLE_SCROLLED(ets));
e_table_set_cursor_row(ets->table, row);
}
int
e_table_scrolled_get_cursor_row (ETableScrolled *ets)
{
g_return_val_if_fail(ets != NULL, -1);
g_return_val_if_fail(E_IS_TABLE_SCROLLED(ets), -1);
return e_table_get_cursor_row(ets->table);
}
void
e_table_scrolled_selected_row_foreach (ETableScrolled *ets,
ETableForeachFunc callback,
gpointer closure)
{
g_return_if_fail(ets != NULL);
g_return_if_fail(E_IS_TABLE_SCROLLED(ets));
e_table_selected_row_foreach(ets->table,
callback,
closure);
}
EPrintable *
e_table_scrolled_get_printable (ETableScrolled *ets)
{
g_return_val_if_fail(ets != NULL, NULL);
g_return_val_if_fail(E_IS_TABLE_SCROLLED(ets), NULL);
return e_table_get_printable(ets->table);
}
static void
ets_get_arg (GtkObject *o, GtkArg *arg, guint arg_id)
{
ETableScrolled *ets = E_TABLE_SCROLLED (o);
gboolean bool_val;
gchar *string_val;
switch (arg_id){
case ARG_TABLE_DRAW_GRID:
gtk_object_get(GTK_OBJECT(ets->table),
"drawgrid", &bool_val,
NULL);
GTK_VALUE_BOOL (*arg) = bool_val;
break;
case ARG_TABLE_DRAW_FOCUS:
gtk_object_get(GTK_OBJECT(ets->table),
"drawfocus", &bool_val,
NULL);
GTK_VALUE_BOOL (*arg) = bool_val;
break;
case ARG_CLICK_TO_ADD_MESSAGE:
gtk_object_get(GTK_OBJECT(ets->table),
"click_to_add_message", &string_val,
NULL);
GTK_VALUE_STRING (*arg) = string_val;
break;
}
}
static void
ets_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
{
ETableScrolled *ets = E_TABLE_SCROLLED (o);
switch (arg_id){
case ARG_LENGTH_THRESHOLD:
gtk_object_set(GTK_OBJECT(ets->table),
"length_threshold", GTK_VALUE_INT (*arg),
NULL);
break;
case ARG_TABLE_DRAW_GRID:
gtk_object_set(GTK_OBJECT(ets->table),
"drawgrid", GTK_VALUE_BOOL (*arg),
NULL);
break;
case ARG_TABLE_DRAW_FOCUS:
gtk_object_set(GTK_OBJECT(ets->table),
"drawfocus", GTK_VALUE_BOOL (*arg),
NULL);
break;
case ARG_CURSOR_MODE:
gtk_object_set(GTK_OBJECT(ets->table),
"cursor_mode", GTK_VALUE_INT (*arg),
NULL);
break;
case ARG_CLICK_TO_ADD_MESSAGE:
gtk_object_set(GTK_OBJECT(ets->table),
"click_to_add_message", GTK_VALUE_STRING (*arg),
NULL);
break;
}
}
static void
e_table_scrolled_class_init (GtkObjectClass *object_class)
{
ETableScrolledClass *klass = E_TABLE_SCROLLED_CLASS(object_class);
parent_class = gtk_type_class (PARENT_TYPE);
object_class->set_arg = ets_set_arg;
object_class->get_arg = ets_get_arg;
klass->cursor_change = NULL;
klass->double_click = NULL;
klass->right_click = NULL;
klass->key_press = NULL;
ets_signals [CURSOR_CHANGE] =
gtk_signal_new ("cursor_change",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (ETableScrolledClass, cursor_change),
gtk_marshal_NONE__INT,
GTK_TYPE_NONE, 1, GTK_TYPE_INT);
ets_signals [DOUBLE_CLICK] =
gtk_signal_new ("double_click",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (ETableScrolledClass, double_click),
gtk_marshal_NONE__INT,
GTK_TYPE_NONE, 1, GTK_TYPE_INT);
ets_signals [RIGHT_CLICK] =
gtk_signal_new ("right_click",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (ETableScrolledClass, right_click),
e_marshal_INT__INT_INT_POINTER,
GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER);
ets_signals [KEY_PRESS] =
gtk_signal_new ("key_press",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (ETableScrolledClass, key_press),
e_marshal_INT__INT_INT_POINTER,
GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER);
gtk_object_class_add_signals (object_class, ets_signals, LAST_SIGNAL);
gtk_object_add_arg_type ("ETableScrolled::drawgrid", GTK_TYPE_BOOL,
GTK_ARG_READWRITE, ARG_TABLE_DRAW_GRID);
gtk_object_add_arg_type ("ETableScrolled::drawfocus", GTK_TYPE_BOOL,
GTK_ARG_READWRITE, ARG_TABLE_DRAW_FOCUS);
gtk_object_add_arg_type ("ETableScrolled::cursor_mode", GTK_TYPE_INT,
GTK_ARG_WRITABLE, ARG_CURSOR_MODE);
gtk_object_add_arg_type ("ETableScrolled::length_threshold", GTK_TYPE_INT,
GTK_ARG_WRITABLE, ARG_LENGTH_THRESHOLD);
gtk_object_add_arg_type ("ETableScrolled::click_to_add_message", GTK_TYPE_STRING,
GTK_ARG_READWRITE, ARG_CLICK_TO_ADD_MESSAGE);
}
E_MAKE_TYPE(e_table_scrolled, "ETableScrolled", ETableScrolled, e_table_scrolled_class_init, e_table_scrolled_init, PARENT_TYPE);