aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/e-table/e-table-subset-variable.c
blob: d429604301d9a6f847f5e03302d1115bb06dc2da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * E-table-subset.c: Implements a table that contains a subset of another table.
 *
 * Author:
 *   Miguel de Icaza (miguel@gnu.org)
 *
 * (C) 1999 Helix Code, Inc.
 */
#include <config.h>
#include <stdlib.h>
#include <gtk/gtksignal.h>
#include <string.h>
#include "e-util/e-util.h"
#include "e-table-subset-variable.h"

#define ETSSV_CLASS(e) ((ETableSubsetVariableClass *)((GtkObject *)e)->klass)

#define PARENT_TYPE E_TABLE_SUBSET_TYPE

#define INCREMENT_AMOUNT 10

static ETableSubsetClass *etssv_parent_class;

static void
etssv_add       (ETableSubsetVariable *etssv,
         gint                  row)
{
    ETableModel *etm = E_TABLE_MODEL(etssv);
    ETableSubset *etss = E_TABLE_SUBSET(etssv);
    
    e_table_model_pre_change(etm);

    if (etss->n_map + 1 > etssv->n_vals_allocated){
        etss->map_table = g_realloc (etss->map_table, (etssv->n_vals_allocated + INCREMENT_AMOUNT) * sizeof(int));
        etssv->n_vals_allocated += INCREMENT_AMOUNT;
    }

    etss->map_table[etss->n_map++] = row;

    e_table_model_row_inserted (etm, etss->n_map - 1);
}

static void
etssv_add_all   (ETableSubsetVariable *etssv)
{
    ETableModel *etm = E_TABLE_MODEL(etssv);
    ETableSubset *etss = E_TABLE_SUBSET(etssv);
    int rows;
    int i;

    e_table_model_pre_change(etm);
    
    rows = e_table_model_row_count(etss->source);
    if (etss->n_map + rows > etssv->n_vals_allocated){
        etssv->n_vals_allocated += MAX(INCREMENT_AMOUNT, rows);
        etss->map_table = g_realloc (etss->map_table, etssv->n_vals_allocated * sizeof(int));
    }
    for (i = 0; i < rows; i++)
        etss->map_table[etss->n_map++] = i;

    e_table_model_changed (etm);
}

static gboolean
etssv_remove    (ETableSubsetVariable *etssv,
         gint                  row)
{
    ETableModel *etm = E_TABLE_MODEL(etssv);
    ETableSubset *etss = E_TABLE_SUBSET(etssv);
    int i;
    
    for (i = 0; i < etss->n_map; i++){
        if (etss->map_table[i] == row) {
            e_table_model_pre_change (etm);
            memmove (etss->map_table + i, etss->map_table + i + 1, (etss->n_map - i - 1) * sizeof(int));
            etss->n_map --;
            
            e_table_model_row_deleted (etm, i);
            return TRUE;
        }
    }
    return FALSE;
}

static void
etssv_class_init (GtkObjectClass *object_class)
{
    ETableSubsetVariableClass *klass = E_TABLE_SUBSET_VARIABLE_CLASS(object_class);
    etssv_parent_class = gtk_type_class (PARENT_TYPE);

    klass->add     = etssv_add;
    klass->add_all = etssv_add_all;
    klass->remove  = etssv_remove;
}

E_MAKE_TYPE(e_table_subset_variable, "ETableSubsetVariable", ETableSubsetVariable, etssv_class_init, NULL, PARENT_TYPE);

ETableModel *
e_table_subset_variable_construct (ETableSubsetVariable *etssv,
                   ETableModel          *source)
{
    if (e_table_subset_construct (E_TABLE_SUBSET(etssv), source, 1) == NULL)
        return NULL;
    E_TABLE_SUBSET(etssv)->n_map = 0;

    return E_TABLE_MODEL (etssv);
}

ETableModel *
e_table_subset_variable_new (ETableModel *source)
{
    ETableSubsetVariable *etssv = gtk_type_new (E_TABLE_SUBSET_VARIABLE_TYPE);

    if (e_table_subset_variable_construct (etssv, source) == NULL){
        gtk_object_destroy (GTK_OBJECT (etssv));
        return NULL;
    }

    return (ETableModel *) etssv;
}

void
e_table_subset_variable_add       (ETableSubsetVariable *etssv,
                   gint                  row)
{
    g_return_if_fail (etssv != NULL);
    g_return_if_fail (E_IS_TABLE_SUBSET_VARIABLE(etssv));

    if (ETSSV_CLASS(etssv)->add)
        ETSSV_CLASS (etssv)->add (etssv, row);
}

void
e_table_subset_variable_add_all   (ETableSubsetVariable *etssv)
{
    g_return_if_fail (etssv != NULL);
    g_return_if_fail (E_IS_TABLE_SUBSET_VARIABLE(etssv));

    if (ETSSV_CLASS(etssv)->add_all)
        ETSSV_CLASS (etssv)->add_all (etssv);
}

gboolean
e_table_subset_variable_remove    (ETableSubsetVariable *etssv,
                   gint                  row)
{
    g_return_val_if_fail (etssv != NULL, FALSE);
    g_return_val_if_fail (E_IS_TABLE_SUBSET_VARIABLE(etssv), FALSE);

    if (ETSSV_CLASS(etssv)->remove)
        return ETSSV_CLASS (etssv)->remove (etssv, row);
    else
        return FALSE;
}

void
e_table_subset_variable_increment (ETableSubsetVariable *etssv,
                   gint                  position,
                   gint                  amount)
{
    int i;
    ETableSubset *etss = E_TABLE_SUBSET(etssv);
    for (i = 0; i < etss->n_map; i++) {
        if (etss->map_table[i] > position)
            etss->map_table[i] += amount;
    }
}

void
e_table_subset_variable_decrement (ETableSubsetVariable *etssv,
                   gint                  position,
                   gint                  amount)
{
    int i;
    ETableSubset *etss = E_TABLE_SUBSET(etssv);
    for (i = 0; i < etss->n_map; i++) {
        if (etss->map_table[i] > position)
            etss->map_table[i] -= amount;
    }
}

void
e_table_subset_variable_set_allocation (ETableSubsetVariable *etssv,
                    gint total)
{
    ETableSubset *etss = E_TABLE_SUBSET(etssv);
    if (total <= 0)
        total = 1;
    if (total > etss->n_map){
        etss->map_table = g_realloc (etss->map_table, total * sizeof(int));
    }
}
an class='deletions'>-7/+5 * Update my ports to use my @FreeBSD.org addressmat2003-08-161-1/+1 * Unbreak by converting CR+LF to LF, as gcc does not seem to be tolerantknu2003-08-141-2/+3 * unbreaking on Alpha (and maybe on other 64bit platforms (untested))oliver2003-08-134-14/+49 * Update to version 3.39krion2003-08-112-2/+2 * Set USE_GCC=2.95 to fix build on 5.x. Mark musicbox and icqnix as BROKENkris2003-08-101-0/+1 * a) Fix buildmaho2003-08-092-12/+60 * Update to 4.3.0.marcus2003-08-083-3/+6 * Backout to 3.5.5maho2003-08-082-2/+3 * As announced on May 6, remove the broken math/siag port.kris2003-08-0813-779/+0 * BROKEN: Does not installkris2003-08-071-0/+2 * BROKEN: does not compilekris2003-08-071-0/+2 * Does not compilekris2003-08-071-0/+2 * Update to 1.3.2bkrion2003-08-053-2/+23 * cosmetic cleanup, no functional changesoliver2003-08-058-56/+44 * Unbreak on -currentkrion2003-08-041-0/+4 * Partially fix the build on -CURRENT (still doesn't build with GCC-3.3.1).ru2003-08-041-3/+8 * Upgrade to 23.0.tg2003-08-043-46/+18 * Because Python2.3 headers define _POSIX_SOURCE and _XOPEN_SOURCE,tg2003-08-041-0/+13 * Fix build after recent sys.mk changeskris2003-08-043-3/+9 * Fix build on 4-STABLE disabiling sanity check.maho2003-08-031-2/+2 * a) Fix build on gcc-3.3.xmaho2003-08-027-6/+63 * - Update to 0.6.1perky2003-08-014-73/+72 * Remove distinfo which is not being used anymore.perky2003-08-011-12/+0 * - Use ports/lang/python's MD5_FILE.perky2003-08-011-3/+4 * Update to 1.3.15. Adds some keyboard shortcuts.naddy2003-08-012-2/+2 * Remove NO_PACKAGE (implied by RESTRICTED) and change RESTRICTED message tokris2003-07-311-3/+1 * Update to 4.2.103.marcus2003-07-313-2/+5 * Fix gcc 3.3 compile failure.naddy2003-07-301-5/+60 * Update to 3.5.7maho2003-07-292-2/+2 * Let be hohest: I really don't have a time now to properly maintain allsobomax2003-07-293-3/+3 * Update KDE to the latest official release, KDE 3.1.3lofi2003-07-294-1/+11 * - Update to version 1.1.0krion2003-07-286-87/+45 * - Do not install useless .la fileskrion2003-07-278-36/+76 * Add more explanations about this software.maho2003-07-251-4/+5 * Update to 0.6perky2003-07-253-18/+31 * mark both conflicting each other (they are installing both a same named binary)oliver2003-07-253-0/+6 * Add simple wrapper to avoid the errormaho2003-07-246-26/+46 * Fixed bison problem.maho2003-07-232-2/+4 * Add metis-edf 3, meshes partionning tool used by Code_Aster.oliver2003-07-237-0/+120 * Change my mail to @FreeBSD.orgkrion2003-07-221-1/+1 * Update to 20030629.arved2003-07-224-53/+107 * distfile (superlu_2.0.tar.gz) is updatedmaho2003-07-221-1/+1 * Fix building under -CURRENT (gcc 3.3) by update to 3.5.7 [1]osa2003-07-214-40/+49 * Don't hardcode libgnugetopt into patch.arved2003-07-201-1/+1 * Fix compile on -CURRENT. Linker is still broken due to broken *mk.marcus2003-07-191-0/+636 * Fix build, and another fixes for building.maho2003-07-195-7/+65 * lp_solve, A free linear programming solver that can processmaho2003-07-197-0/+130 * MASTER_SITES has been subjected to change.maho2003-07-191-1/+1 * Update to 4.2.99.marcus2003-07-163-2/+8 * Do a more complete upgrade.joe2003-07-154-536/+26 * Update to 2.1.50.nork2003-07-154-4/+4 * Upgrade port to version 0.8.4.joe2003-07-154-4/+4 * Update to 1.3.14. Minor changes only.naddy2003-07-142-2/+2 * get rid of libgnugetopt dependency for -CURRENT,sf2003-07-144-16/+18 * get rid of libgnugetopt dependency for -CURRENT,sf2003-07-141-2/+2 * Fix suffix of a patch file.nork2003-07-141-1/+1 * Added RESTRICTED and NO_PACKAGE. They should also be needed.maho2003-07-121-0/+2 * Add new port math/fbm.maho2003-07-128-0/+648 * Add new port superlu_mtmaho2003-07-1211-0/+185 * Fix a typo and Don't remove LAPACK2.nork2003-07-122-55/+4 * Don't build a subset of BLAS and ARPACK2 and Use external ones.nork2003-07-125-38/+109 * Correct MASTER_SITES.tg2003-07-101-2/+2 * Update to 1.1.2. Adds French translation.naddy2003-07-084-58/+3 * Upgrade to 2.4.3.tg2003-07-074-13/+26 * update misc/gretl: 1.0.8 --> 1.0.9daichi2003-07-075-23/+75 * Update to 1.9.kuriyama2003-07-064-9/+11 * 1. update to 3.5.6maho2003-07-033-21/+20 * build both threaded/non-threaded librariesmaho2003-07-035-35/+119 * - add CONFLICTSnetchild2003-07-011-0/+2 * Add CONFLICTS.netchild2003-07-012-2/+4 * update math/ploticus:daichi2003-07-013-91/+28 * fix man: math/plplotdaichi2003-07-011-1/+2 * Fix for unfetchmaho2003-07-011-2/+2 * update to 3.5.5maho2003-07-013-21/+20 * Add dependency for gmakemaho2003-07-011-2/+0 * Add a conflict for ploticus, slffea and swi-pl.arved2003-06-291-1/+1 * IGNORE should be used instead of BROKEN to indicate that a portnaddy2003-06-271-1/+1 * Update to 1.3.1arved2003-06-269-62/+7 * Import galculator 1.1.1.naddy2003-06-268-0/+132 * fix the MAINTAINER fieldoliver2003-06-241-1/+1 * Update to 1.0.55arved2003-06-237-219/+143 * Update to 0.39foxfair2003-06-223-7/+6 * PR: 52286foxfair2003-06-213-14/+17 * Update to 4.1.nork2003-06-219-155/+143 * fix for alpha builddaichi2003-06-191-10/+10 * Remove dependency on blas, and unbreak the build.kris2003-06-192-6/+15 * Update scilab to make use of math/atlas (some speed improvement).nork2003-06-181-2/+6 * Utilize USE_GNOME= libgsf.adamw2003-06-171-3/+1 * . Workaround a problem in gcc 2.95.4 when compiling with -march=pentiumpro.glewis2003-06-172-1/+22 * o Enable load *.oct files. [1]nork2003-06-154-120/+280 * upgrade to 1.7.0ijliao2003-06-139-1272/+1599 * Remove REINPLACE commands that were rolled into gnomehack.adamw2003-06-123-10/+0 * * Update to 1.1.19 (Now with graphing support!)marcus2003-06-125-28/+91 * 1. make atlas thread safemaho2003-06-113-5/+40 * 1. correct pkg-plistmaho2003-06-112-4/+2 * Update to 2.5.2maho2003-06-113-6/+11 * Forgot to add files/patch-make.incmaho2003-06-111-0/+42 * Honor CFLAGS, CC and so on.maho2003-06-111-0/+8 * 1. using ATLAS, faster blas implementation.maho2003-06-117-60/+45 * New port: math/fung-calcfjoe2003-06-1011-0/+159 * Some clean up and enhancementmaho2003-06-103-82/+76 * 1. Correct wrong dependency for Lapackmaho2003-06-102-4/+4 * Update to version 4.0.demon2003-06-103-3/+4 * Update to 2.1.49.nork2003-06-104-10/+20 * o Update to 2.1.48.nork2003-06-10