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
293 lines
8.4 KiB
C
293 lines
8.4 KiB
C
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
|
/*
|
|
* e-table-config-field.c
|
|
* 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 "gal/util/e-util.h"
|
|
#include "e-table-config-field.h"
|
|
|
|
#define PARENT_TYPE (gtk_vbox_get_type())
|
|
|
|
static GtkVBoxClass *etcf_parent_class;
|
|
|
|
static void
|
|
etcf_destroy (GtkObject *object)
|
|
{
|
|
ETableConfigField *etcf = E_TABLE_CONFIG_FIELD (object);
|
|
|
|
gtk_object_unref(GTK_OBJECT(etcf->spec));
|
|
gtk_object_unref(GTK_OBJECT(etcf->sort_info));
|
|
|
|
GTK_OBJECT_CLASS (etcf_parent_class)->destroy (object);
|
|
}
|
|
|
|
static void
|
|
etcf_class_init (GtkObjectClass *klass)
|
|
{
|
|
etcf_parent_class = gtk_type_class (PARENT_TYPE);
|
|
|
|
klass->destroy = etcf_destroy;
|
|
}
|
|
|
|
static void
|
|
etcf_init (ETableConfigField *etcf)
|
|
{
|
|
etcf->spec = NULL;
|
|
etcf->sort_info = NULL;
|
|
|
|
etcf->combo = NULL;
|
|
etcf->radio_ascending = NULL;
|
|
etcf->radio_descending = NULL;
|
|
etcf->child_fields = NULL;
|
|
}
|
|
|
|
E_MAKE_TYPE(e_table_config_field, "ETableConfigField", ETableConfigField, etcf_class_init, etcf_init, PARENT_TYPE);
|
|
|
|
ETableConfigField *
|
|
e_table_config_field_new (ETableSpecification *spec,
|
|
ETableSortInfo *sort_info,
|
|
gboolean grouping)
|
|
{
|
|
ETableConfigField *etcf = gtk_type_new (E_TABLE_CONFIG_FIELD_TYPE);
|
|
|
|
e_table_config_field_construct (etcf, spec, sort_info, grouping);
|
|
|
|
return (ETableConfigField *) etcf;
|
|
}
|
|
|
|
inline static int
|
|
etcf_get_count (ETableConfigField *etcf)
|
|
{
|
|
if (etcf->grouping)
|
|
return e_table_sort_info_grouping_get_count(etcf->sort_info);
|
|
else
|
|
return e_table_sort_info_sorting_get_count(etcf->sort_info);
|
|
}
|
|
|
|
inline static ETableSortColumn
|
|
etcf_get_nth (ETableConfigField *etcf)
|
|
{
|
|
if (etcf->grouping)
|
|
return e_table_sort_info_grouping_get_nth(etcf->sort_info, etcf->n);
|
|
else
|
|
return e_table_sort_info_sorting_get_nth(etcf->sort_info, etcf->n);
|
|
}
|
|
|
|
inline static void
|
|
etcf_set_nth (ETableConfigField *etcf, ETableSortColumn column)
|
|
{
|
|
if (etcf->grouping)
|
|
e_table_sort_info_grouping_set_nth(etcf->sort_info, etcf->n, column);
|
|
else
|
|
e_table_sort_info_sorting_set_nth(etcf->sort_info, etcf->n, column);
|
|
}
|
|
|
|
inline static void
|
|
etcf_truncate (ETableConfigField *etcf)
|
|
{
|
|
if (etcf->grouping)
|
|
e_table_sort_info_grouping_truncate(etcf->sort_info, etcf->n);
|
|
else
|
|
e_table_sort_info_sorting_truncate(etcf->sort_info, etcf->n);
|
|
}
|
|
|
|
static void
|
|
etcf_set_sensitivity(ETableConfigField *etcf)
|
|
{
|
|
int count = etcf_get_count(etcf);
|
|
|
|
if (etcf->n >= count) {
|
|
gtk_widget_set_sensitive(etcf->radio_ascending, FALSE);
|
|
gtk_widget_set_sensitive(etcf->radio_descending, FALSE);
|
|
if (etcf->child_fields)
|
|
gtk_widget_set_sensitive(etcf->child_fields, FALSE);
|
|
} else {
|
|
gtk_widget_set_sensitive(etcf->radio_ascending, TRUE);
|
|
gtk_widget_set_sensitive(etcf->radio_descending, TRUE);
|
|
if (etcf->child_fields)
|
|
gtk_widget_set_sensitive(etcf->child_fields, TRUE);
|
|
}
|
|
}
|
|
|
|
static void
|
|
toggled(GtkWidget *widget, ETableConfigField *etcf)
|
|
{
|
|
int count;
|
|
|
|
count = etcf_get_count(etcf);
|
|
if (count > etcf->n) {
|
|
ETableSortColumn sort_column;
|
|
|
|
sort_column = etcf_get_nth(etcf);
|
|
sort_column.ascending = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(etcf->radio_ascending));
|
|
etcf_set_nth(etcf, sort_column);
|
|
}
|
|
}
|
|
|
|
static void
|
|
changed(GtkWidget *widget, ETableConfigField *etcf)
|
|
{
|
|
ETableColumnSpecification **column;
|
|
gchar *text;
|
|
|
|
text = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(etcf->combo)->entry));
|
|
for (column = etcf->spec->columns; *column; column++) {
|
|
if (!strcmp((*column)->title_, text)) {
|
|
ETableSortColumn sort_column;
|
|
|
|
sort_column.ascending = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(etcf->radio_ascending));
|
|
sort_column.column = (*column)->model_col;
|
|
|
|
etcf_set_nth(etcf, sort_column);
|
|
etcf_set_sensitivity(etcf);
|
|
return;
|
|
}
|
|
}
|
|
etcf_truncate(etcf);
|
|
etcf_set_sensitivity(etcf);
|
|
}
|
|
|
|
static void
|
|
etcf_setup(ETableConfigField *etcf)
|
|
{
|
|
int count;
|
|
GList *list = NULL;
|
|
ETableColumnSpecification **column;
|
|
ETableColumnSpecification *chosen_column = NULL;
|
|
int model_col = -1;
|
|
|
|
etcf_set_sensitivity(etcf);
|
|
|
|
count = etcf_get_count(etcf);
|
|
|
|
if (count > etcf->n) {
|
|
ETableSortColumn sort_column;
|
|
|
|
sort_column = etcf_get_nth(etcf);
|
|
model_col = sort_column.column;
|
|
if (sort_column.ascending)
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(etcf->radio_ascending), TRUE);
|
|
else
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(etcf->radio_descending), TRUE);
|
|
}
|
|
|
|
for (column = etcf->spec->columns; *column; column++) {
|
|
list = g_list_prepend(list, (*column)->title_);
|
|
if (count > etcf->n && chosen_column == NULL && (*column)->model_col == model_col) {
|
|
chosen_column = *column;
|
|
}
|
|
}
|
|
list = g_list_reverse(list);
|
|
list = g_list_prepend(list, "None");
|
|
|
|
gtk_combo_set_popdown_strings(GTK_COMBO(etcf->combo), list);
|
|
g_list_free(list);
|
|
|
|
if (chosen_column) {
|
|
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(etcf->combo)->entry), chosen_column->title_);
|
|
} else {
|
|
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(etcf->combo)->entry), "None");
|
|
}
|
|
|
|
gtk_signal_connect(GTK_OBJECT(GTK_COMBO(etcf->combo)->entry), "changed",
|
|
GTK_SIGNAL_FUNC(changed), etcf);
|
|
gtk_signal_connect(GTK_OBJECT(etcf->radio_ascending), "toggled",
|
|
GTK_SIGNAL_FUNC(toggled), etcf);
|
|
gtk_signal_connect(GTK_OBJECT(etcf->radio_descending), "toggled",
|
|
GTK_SIGNAL_FUNC(toggled), etcf);
|
|
}
|
|
|
|
static ETableConfigField *
|
|
e_table_config_field_construct_nth (ETableConfigField *etcf,
|
|
ETableSpecification *spec,
|
|
ETableSortInfo *sort_info,
|
|
gboolean grouping,
|
|
int n)
|
|
{
|
|
GtkWidget *frame;
|
|
GtkWidget *internal_hbox;
|
|
GtkWidget *internal_vbox1;
|
|
GtkWidget *internal_vbox2;
|
|
|
|
etcf->spec = spec;
|
|
gtk_object_ref(GTK_OBJECT(spec));
|
|
|
|
etcf->sort_info = sort_info;
|
|
gtk_object_ref(GTK_OBJECT(sort_info));
|
|
|
|
etcf->grouping = grouping;
|
|
etcf->n = n;
|
|
|
|
gtk_box_set_spacing(GTK_BOX(etcf), 6);
|
|
|
|
frame = gtk_frame_new(n > 0 ? _("Then By") : (grouping ? _("Group By") : _("Sort By")));
|
|
gtk_box_pack_start(GTK_BOX(etcf), frame, FALSE, FALSE, 0);
|
|
|
|
internal_hbox = gtk_hbox_new(FALSE, 6);
|
|
gtk_container_add(GTK_CONTAINER(frame), internal_hbox);
|
|
gtk_container_set_border_width(GTK_CONTAINER(internal_hbox), 6);
|
|
|
|
internal_vbox1 = gtk_vbox_new(FALSE, 6);
|
|
gtk_box_pack_start(GTK_BOX(internal_hbox), internal_vbox1, FALSE, FALSE, 0);
|
|
|
|
etcf->combo = gtk_combo_new();
|
|
gtk_box_pack_start(GTK_BOX(internal_vbox1), etcf->combo, FALSE, FALSE, 0);
|
|
|
|
internal_vbox2 = gtk_vbox_new(FALSE, 6);
|
|
gtk_box_pack_start(GTK_BOX(internal_hbox), internal_vbox2, FALSE, FALSE, 0);
|
|
|
|
etcf->radio_ascending = gtk_radio_button_new_with_label (NULL, _("Ascending"));
|
|
gtk_box_pack_start(GTK_BOX(internal_vbox2), etcf->radio_ascending, FALSE, FALSE, 0);
|
|
|
|
etcf->radio_descending = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON(etcf->radio_ascending), _("Descending"));
|
|
gtk_box_pack_start(GTK_BOX(internal_vbox2), etcf->radio_descending, FALSE, FALSE, 0);
|
|
|
|
if (n < 3) {
|
|
etcf->child_fields = GTK_WIDGET(gtk_type_new (E_TABLE_CONFIG_FIELD_TYPE));
|
|
e_table_config_field_construct_nth(E_TABLE_CONFIG_FIELD(etcf->child_fields), spec, sort_info, grouping, n + 1);
|
|
gtk_box_pack_start(GTK_BOX(etcf), etcf->child_fields, FALSE, FALSE, 0);
|
|
gtk_widget_show(etcf->child_fields);
|
|
} else
|
|
etcf->child_fields = NULL;
|
|
|
|
etcf_setup(etcf);
|
|
|
|
gtk_widget_show(etcf->radio_descending);
|
|
gtk_widget_show(etcf->radio_ascending);
|
|
gtk_widget_show(internal_vbox2);
|
|
gtk_widget_show(etcf->combo);
|
|
gtk_widget_show(internal_vbox1);
|
|
gtk_widget_show(internal_hbox);
|
|
gtk_widget_show(frame);
|
|
return etcf;
|
|
}
|
|
|
|
ETableConfigField *
|
|
e_table_config_field_construct (ETableConfigField *etcf,
|
|
ETableSpecification *spec,
|
|
ETableSortInfo *sort_info,
|
|
gboolean grouping)
|
|
{
|
|
return e_table_config_field_construct_nth(etcf, spec, sort_info, grouping, 0);
|
|
}
|