29 #include <glib/gi18n.h>
31 #include "gnc-amount-edit.h"
34 #include "search-numeric.h"
35 #include "search-core-utils.h"
48 static void gnc_search_numeric_finalize (GObject *obj);
60 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_SEARCH_NUMERIC, GNCSearchNumericPrivate))
65 gnc_search_numeric_get_type (
void)
67 static GType type = 0;
76 (GClassInitFunc)gnc_search_numeric_class_init,
81 (GInstanceInitFunc)gnc_search_numeric_init,
84 type = g_type_register_static (GNC_TYPE_SEARCH_CORE_TYPE,
95 GObjectClass *object_class;
98 object_class = G_OBJECT_CLASS (klass);
99 parent_class = g_type_class_peek_parent (klass);
101 object_class->finalize = gnc_search_numeric_finalize;
104 gnc_search_core_type->editable_enters = editable_enters;
105 gnc_search_core_type->grab_focus = grab_focus;
106 gnc_search_core_type->validate = gncs_validate;
107 gnc_search_core_type->get_widget = gncs_get_widget;
108 gnc_search_core_type->get_predicate = gncs_get_predicate;
109 gnc_search_core_type->clone = gncs_clone;
117 o->value = gnc_numeric_zero ();
118 o->how = QOF_COMPARE_EQUAL;
119 o->option = QOF_NUMERIC_MATCH_ANY;
123 gnc_search_numeric_finalize (GObject *obj)
126 g_assert (IS_GNCSEARCH_NUMERIC (o));
128 G_OBJECT_CLASS (parent_class)->finalize(obj);
139 gnc_search_numeric_new (
void)
153 gnc_search_numeric_debcred_new (
void)
158 o = g_object_new(GNC_TYPE_SEARCH_NUMERIC, NULL);
160 priv->is_debcred = TRUE;
167 g_return_if_fail (fi);
168 g_return_if_fail (IS_GNCSEARCH_NUMERIC (fi));
176 g_return_if_fail (fi);
177 g_return_if_fail (IS_GNCSEARCH_NUMERIC (fi));
184 g_return_if_fail (fi);
185 g_return_if_fail (IS_GNCSEARCH_NUMERIC (fi));
193 gboolean valid = TRUE;
195 g_return_val_if_fail (fi, FALSE);
196 g_return_val_if_fail (IS_GNCSEARCH_NUMERIC (fi), FALSE);
206 fe->value = gnc_amount_edit_get_amount (entry);
218 combo = GTK_COMBO_BOX(gnc_combo_box_new_search());
219 gnc_combo_box_search_add(combo, (priv->is_debcred ?
220 _(
"less than") : _(
"is less than")),
222 gnc_combo_box_search_add(combo, (priv->is_debcred ?
223 _(
"less than or equal to") :
224 _(
"is less than or equal to")),
226 gnc_combo_box_search_add(combo, (priv->is_debcred ?
227 _(
"equal to") : _(
"equals")),
229 gnc_combo_box_search_add(combo, (priv->is_debcred ?
230 _(
"not equal to") : _(
"does not equal")),
232 gnc_combo_box_search_add(combo, (priv->is_debcred ?
233 _(
"greater than") : _(
"is greater than")),
235 gnc_combo_box_search_add(combo, (priv->is_debcred ?
236 _(
"greater than or equal to") :
237 _(
"is greater than or equal to")),
240 gnc_combo_box_search_changed(combo, &fi->how);
241 gnc_combo_box_search_set_active(combo, fi->how ? fi->how : QOF_COMPARE_LT);
243 return GTK_WIDGET(combo);
252 combo = GTK_COMBO_BOX(gnc_combo_box_new_search());
253 gnc_combo_box_search_add(combo, _(
"has credits or debits"), QOF_NUMERIC_MATCH_ANY);
254 gnc_combo_box_search_add(combo, _(
"has debits"), QOF_NUMERIC_MATCH_DEBIT);
255 gnc_combo_box_search_add(combo, _(
"has credits"), QOF_NUMERIC_MATCH_CREDIT);
256 gnc_combo_box_search_changed(combo, &fi->option);
257 gnc_combo_box_search_set_active(combo, fi->option ? fi->option : QOF_NUMERIC_MATCH_ANY);
259 return GTK_WIDGET(combo);
268 g_return_if_fail (fi);
269 g_return_if_fail (IS_GNCSEARCH_NUMERIC (fi));
273 gtk_widget_grab_focus (priv->entry);
282 g_return_if_fail (fi);
283 g_return_if_fail (IS_GNCSEARCH_NUMERIC (fi));
287 gtk_entry_set_activates_default(GTK_ENTRY (priv->entry), TRUE);
293 GtkWidget *entry, *menu, *box;
297 g_return_val_if_fail (fi, NULL);
298 g_return_val_if_fail (IS_GNCSEARCH_NUMERIC (fi), NULL);
301 box = gtk_hbox_new (FALSE, 3);
304 if (priv->is_debcred)
306 menu = make_option_menu (fe);
307 gtk_box_pack_start (GTK_BOX (box), menu, FALSE, FALSE, 3);
310 menu = make_how_menu (fe);
311 gtk_box_pack_start (GTK_BOX (box), menu, FALSE, FALSE, 3);
314 entry = gnc_amount_edit_new ();
315 gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (entry), fi->value);
316 g_signal_connect (G_OBJECT (entry),
"amount_changed", G_CALLBACK (entry_changed), fe);
317 gtk_box_pack_start (GTK_BOX (box), entry, FALSE, FALSE, 3);
318 priv->gae = GNC_AMOUNT_EDIT (entry);
319 priv->entry = gnc_amount_edit_gtk_entry (GNC_AMOUNT_EDIT (entry));
330 g_return_val_if_fail (fi, NULL);
331 g_return_val_if_fail (IS_GNCSEARCH_NUMERIC (fi), NULL);
335 entry_changed (priv->gae, fi);
337 return qof_query_numeric_predicate (fi->how, fi->option, fi->value);
345 g_return_val_if_fail (fse, NULL);
346 g_return_val_if_fail (IS_GNCSEARCH_NUMERIC (fse), NULL);
347 fse_priv = _PRIVATE(fse);
349 se = gnc_search_numeric_new ();
350 gnc_search_numeric_set_value (se, fse->value);
351 gnc_search_numeric_set_how (se, fse->how);
352 se_priv = _PRIVATE(se);
353 gnc_search_numeric_set_option (se, fse->option);
354 se_priv->is_debcred = fse_priv->is_debcred;