5 * Andreas J. Guelzow <aguelzow@pyrshep.ca>
7 * (C) Copyright 2010 by Andreas J. Guelzow <aguelzow@pyrshep.ca>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, see <https://www.gnu.org/licenses/>.
23 #include <gnumeric-config.h>
27 #include <sheet-view.h>
28 #include <sheet-control-gui.h>
30 #include <wbc-gtk-impl.h>
33 #include <gsf/gsf-impl-utils.h>
34 #include <glib/gi18n-lib.h>
36 /* ------------------------------------------------------------------------- */
38 static GObjectClass
*gnm_undo_colrow_restore_state_group_parent_class
;
41 gnm_undo_colrow_restore_state_group_finalize (GObject
*o
)
43 GnmUndoColrowRestoreStateGroup
*ua
= (GnmUndoColrowRestoreStateGroup
*)o
;
45 colrow_state_group_destroy (ua
->saved_state
);
46 ua
->saved_state
= NULL
;
47 colrow_index_list_destroy (ua
->selection
);
50 G_OBJECT_CLASS (gnm_undo_colrow_restore_state_group_parent_class
)->finalize (o
);
54 gnm_undo_colrow_restore_state_group_undo (GOUndo
*u
, G_GNUC_UNUSED gpointer data
)
56 GnmUndoColrowRestoreStateGroup
*ua
= (GnmUndoColrowRestoreStateGroup
*)u
;
58 colrow_restore_state_group (ua
->sheet
, ua
->is_cols
, ua
->selection
, ua
->saved_state
);
62 gnm_undo_colrow_restore_state_group_class_init (GObjectClass
*gobject_class
)
64 GOUndoClass
*uclass
= (GOUndoClass
*)gobject_class
;
66 gnm_undo_colrow_restore_state_group_parent_class
= g_type_class_peek_parent (gobject_class
);
68 gobject_class
->finalize
= gnm_undo_colrow_restore_state_group_finalize
;
69 uclass
->undo
= gnm_undo_colrow_restore_state_group_undo
;
73 GSF_CLASS (GnmUndoColrowRestoreStateGroup
, gnm_undo_colrow_restore_state_group
,
74 gnm_undo_colrow_restore_state_group_class_init
, NULL
, GO_TYPE_UNDO
)
77 * gnm_undo_colrow_restore_state_group_new:
79 * Returns: a new undo object.
83 gnm_undo_colrow_restore_state_group_new (Sheet
*sheet
, gboolean is_cols
,
84 ColRowIndexList
*selection
,
85 ColRowStateGroup
*saved_state
)
87 GnmUndoColrowRestoreStateGroup
*ua
= g_object_new (GNM_TYPE_UNDO_COLROW_RESTORE_STATE_GROUP
, NULL
);
90 ua
->is_cols
= is_cols
;
91 ua
->selection
= selection
;
92 ua
->saved_state
= saved_state
;
97 /* ------------------------------------------------------------------------- */
99 static GObjectClass
*gnm_undo_colrow_set_sizes_parent_class
;
102 gnm_undo_colrow_set_sizes_finalize (GObject
*o
)
104 GnmUndoColrowSetSizes
*ua
= (GnmUndoColrowSetSizes
*)o
;
106 colrow_index_list_destroy (ua
->selection
);
107 ua
->selection
= NULL
;
109 G_OBJECT_CLASS (gnm_undo_colrow_set_sizes_parent_class
)->finalize (o
);
113 gnm_undo_colrow_set_sizes_undo (GOUndo
*u
, G_GNUC_UNUSED gpointer data
)
115 GnmUndoColrowSetSizes
*ua
= (GnmUndoColrowSetSizes
*)u
;
116 ColRowStateGroup
*group
;
118 group
= colrow_set_sizes (ua
->sheet
, ua
->is_cols
, ua
->selection
, ua
->new_size
,
120 colrow_state_group_destroy (group
);
124 gnm_undo_colrow_set_sizes_class_init (GObjectClass
*gobject_class
)
126 GOUndoClass
*uclass
= (GOUndoClass
*)gobject_class
;
128 gnm_undo_colrow_set_sizes_parent_class
= g_type_class_peek_parent (gobject_class
);
130 gobject_class
->finalize
= gnm_undo_colrow_set_sizes_finalize
;
131 uclass
->undo
= gnm_undo_colrow_set_sizes_undo
;
135 GSF_CLASS (GnmUndoColrowSetSizes
, gnm_undo_colrow_set_sizes
,
136 gnm_undo_colrow_set_sizes_class_init
, NULL
, GO_TYPE_UNDO
)
139 * gnm_undo_colrow_set_sizes_new:
141 * If r is non-null and new_size < 0, selection is ignored.
143 * Returns: a new undo object.
147 gnm_undo_colrow_set_sizes_new (Sheet
*sheet
, gboolean is_cols
,
148 ColRowIndexList
*selection
,
149 int new_size
, GnmRange
const *r
)
151 GnmUndoColrowSetSizes
*ua
;
153 g_return_val_if_fail (selection
!= NULL
|| (r
!= NULL
&& new_size
== -1), NULL
);
155 ua
= g_object_new (GNM_TYPE_UNDO_COLROW_SET_SIZES
, NULL
);
158 ua
->is_cols
= is_cols
;
159 ua
->new_size
= new_size
;
161 if (r
== NULL
|| new_size
>= 0) {
162 ua
->selection
= selection
;
169 first
= r
->start
.col
;
171 ua
->from
= r
->start
.row
;
174 first
= r
->start
.row
;
176 ua
->from
= r
->start
.col
;
179 ua
->selection
= colrow_get_index_list (first
, last
, NULL
);
185 /* ------------------------------------------------------------------------- */
187 static GObjectClass
*gnm_undo_filter_set_condition_parent_class
;
190 gnm_undo_filter_set_condition_finalize (GObject
*o
)
192 GnmUndoFilterSetCondition
*ua
= (GnmUndoFilterSetCondition
*)o
;
194 gnm_filter_condition_free (ua
->cond
);
197 G_OBJECT_CLASS (gnm_undo_filter_set_condition_parent_class
)->finalize (o
);
201 cb_filter_set_condition_undo (GnmColRowIter
const *iter
, gint
*count
)
203 if (iter
->cri
->visible
)
209 cb_filter_set_condition_undo_set_pb (SheetControl
*control
, char *text
)
211 SheetControlGUI
*scg
= (SheetControlGUI
*) control
;
212 WBCGtk
*wbcg
= scg_wbcg (scg
);
214 gtk_progress_bar_set_text
215 (GTK_PROGRESS_BAR (wbcg
->progress_bar
), text
);
219 gnm_undo_filter_set_condition_undo (GOUndo
*u
, G_GNUC_UNUSED gpointer data
)
221 GnmUndoFilterSetCondition
*ua
= (GnmUndoFilterSetCondition
*)u
;
226 gnm_filter_set_condition (ua
->filter
, ua
->i
,
227 gnm_filter_condition_dup (ua
->cond
), TRUE
);
228 sheet_update (ua
->filter
->sheet
);
230 sheet_colrow_foreach (ua
->filter
->sheet
, FALSE
,
231 ua
->filter
->r
.start
.row
+ 1,
232 ua
->filter
->r
.end
.row
,
233 (ColRowHandler
) cb_filter_set_condition_undo
,
235 if (ua
->filter
->r
.end
.row
- ua
->filter
->r
.start
.row
> 10) {
236 /* xgettext: The first %d gives the number of rows that match. */
237 /* The second %d gives the total number of rows. Assume that the */
238 /* total number of rows is always large (>10). */
239 /* Note that the english "matches" or "match" is the verb of this sentence! */
240 /* There is no explicit noun associated with the second %d in english, the */
241 /* meaning is really "%d rows of all %d rows match" */
242 /* This is input to ngettext. */
243 format
= ngettext ("%d row of %d matches",
244 "%d rows of %d match",
246 text
= g_strdup_printf (format
, count
,
247 ua
->filter
->r
.end
.row
-
248 ua
->filter
->r
.start
.row
);
250 /* xgettext: The %d gives the number of rows that match. */
251 /* This is input to ngettext. */
252 format
= ngettext ("%d row matches",
255 text
= g_strdup_printf (format
, count
);
258 SHEET_FOREACH_CONTROL (ua
->filter
->sheet
, view
, control
, cb_filter_set_condition_undo_set_pb (control
, text
););
264 gnm_undo_filter_set_condition_class_init (GObjectClass
*gobject_class
)
266 GOUndoClass
*uclass
= (GOUndoClass
*)gobject_class
;
268 gnm_undo_filter_set_condition_parent_class
= g_type_class_peek_parent
271 gobject_class
->finalize
= gnm_undo_filter_set_condition_finalize
;
272 uclass
->undo
= gnm_undo_filter_set_condition_undo
;
276 GSF_CLASS (GnmUndoFilterSetCondition
, gnm_undo_filter_set_condition
,
277 gnm_undo_filter_set_condition_class_init
, NULL
, GO_TYPE_UNDO
)
280 * gnm_undo_filter_set_condition_new:
282 * if (retrieve_from_filter), cond is ignored
284 * Returns: a new undo object.
288 gnm_undo_filter_set_condition_new (GnmFilter
*filter
, unsigned i
,
289 GnmFilterCondition
*cond
,
290 gboolean retrieve_from_filter
)
292 GnmUndoFilterSetCondition
*ua
;
294 g_return_val_if_fail (filter
!= NULL
, NULL
);
295 g_return_val_if_fail (i
< filter
->fields
->len
, NULL
);
297 ua
= g_object_new (GNM_TYPE_UNDO_FILTER_SET_CONDITION
, NULL
);
302 if (retrieve_from_filter
)
303 ua
->cond
= gnm_filter_condition_dup
304 (gnm_filter_get_condition (filter
, i
));
310 /* ------------------------------------------------------------------------- */