GnuCash c935c2f+
Loading...
Searching...
No Matches
Files | Data Structures
GncCurrencyEdit

Files

file  gnc-currency-edit.h
 Currency selection widget.
 

Data Structures

struct  _GNCCurrencyEdit
 

Basic Object Implementation

enum  { PROP_0 , PROP_GCE_MNEMONIC , N_PROPERTIES }
 
enum  { CURRENCY_COL_NAME , CURRENCY_COL_NORMALIZED_FOLDED , NUM_CURRENCY_COLS }
 
GtkWidget * gnc_currency_edit_new (void)
 Create a new GNCCurrencyEdit widget which can be used to provide an easy way to enter ISO currency codes.
 

Get/Set Functions

void gnc_currency_edit_set_currency (GNCCurrencyEdit *gce, const gnc_commodity *currency)
 Set the widget to display a certain currency name.
 
gnc_commodity * gnc_currency_edit_get_currency (GNCCurrencyEdit *gce)
 Retrieve the displayed currency of the widget.
 
void gnc_currency_edit_clear_display (GNCCurrencyEdit *gce)
 Clear the displayed currency of the widget.
 

Basic Object Implementation

#define GNC_TYPE_CURRENCY_EDIT   (gnc_currency_edit_get_type())
 

Detailed Description

Macro Definition Documentation

◆ GNC_TYPE_CURRENCY_EDIT

#define GNC_TYPE_CURRENCY_EDIT   (gnc_currency_edit_get_type())

Definition at line 67 of file gnc-currency-edit.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Definition at line 86 of file gnc-currency-edit.cpp.

87{
88 PROP_0,
89
90 PROP_GCE_MNEMONIC,
91
92 N_PROPERTIES
93};

◆ anonymous enum

anonymous enum

Definition at line 262 of file gnc-currency-edit.cpp.

263{
264 CURRENCY_COL_NAME,
265 CURRENCY_COL_NORMALIZED_FOLDED,
266 NUM_CURRENCY_COLS
267};

Function Documentation

◆ gnc_currency_edit_clear_display()

void gnc_currency_edit_clear_display ( GNCCurrencyEdit *  gce)

Clear the displayed currency of the widget.

This will clear the currency being displayed just like when first created but it still returns the default currency as usual

Parameters
gceThe currency editor widget whose values should be retrieved.

Definition at line 458 of file gnc-currency-edit.cpp.

459{
460 GtkTreeModel *model;
461 GtkWidget *entry;
462
463 g_return_if_fail(gce != nullptr);
464 g_return_if_fail(GNC_IS_CURRENCY_EDIT(gce));
465
466 model = gtk_combo_box_get_model (GTK_COMBO_BOX(gce));
467
468 entry = gtk_bin_get_child (GTK_BIN(gce));
469
470 g_object_ref (model);
471
472 g_signal_handlers_block_by_func (G_OBJECT(gce),
473 (gpointer)gnc_currency_edit_active_changed, gce);
474
475 gtk_combo_box_set_model (GTK_COMBO_BOX(gce), nullptr);
476 gtk_entry_set_text (GTK_ENTRY(entry),"");
477 gtk_combo_box_set_active (GTK_COMBO_BOX(gce), -1);
478 gtk_combo_box_set_model (GTK_COMBO_BOX(gce), model);
479
480 g_signal_handlers_block_by_func (G_OBJECT(gce),
481 (gpointer)gnc_currency_edit_active_changed, gce);
482
483 g_object_unref (model);
484}

◆ gnc_currency_edit_get_currency()

gnc_commodity * gnc_currency_edit_get_currency ( GNCCurrencyEdit *  gce)

Retrieve the displayed currency of the widget.

Parameters
gceThe currency editor widget whose values should be retrieved.
Returns
A pointer to the selected currency (a gnc_commodity structure).

Definition at line 417 of file gnc-currency-edit.cpp.

418{
419 gnc_commodity *commodity;
420 char *mnemonic, *name;
421 GtkTreeModel *model;
422 GtkTreeIter iter;
423
424 g_return_val_if_fail(gce != nullptr, nullptr);
425 g_return_val_if_fail(GNC_IS_CURRENCY_EDIT(gce), nullptr);
426
427 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(gce), &iter))
428 {
429 model = gtk_combo_box_get_model(GTK_COMBO_BOX(gce));
430 gtk_tree_model_get (model, &iter, 0, &mnemonic, -1);
431
432 name = strchr(mnemonic, ' ');
433 if (name != nullptr)
434 *name = '\0';
435 commodity = gnc_commodity_table_lookup (gnc_get_current_commodities (),
436 GNC_COMMODITY_NS_CURRENCY,
437 mnemonic);
438 g_free(mnemonic);
439 }
440 else
441 {
442 g_warning("Combo box returned 'inactive'. Using locale default currency.");
443 commodity = gnc_locale_default_currency();
444 }
445
446
447 return commodity;
448}
gnc_commodity * gnc_locale_default_currency(void)
Returns the default currency of the current locale.

◆ gnc_currency_edit_new()

GtkWidget * gnc_currency_edit_new ( void  )

Create a new GNCCurrencyEdit widget which can be used to provide an easy way to enter ISO currency codes.

Returns
A GNCCurrencyEdit widget.

Definition at line 344 of file gnc-currency-edit.cpp.

345{
346 GNCCurrencyEdit *gce;
347 GtkListStore *store;
348 GtkEntryCompletion* completion;
349
350 store = gtk_list_store_new (NUM_CURRENCY_COLS, G_TYPE_STRING, G_TYPE_STRING);
351 gce = GNC_CURRENCY_EDIT(g_object_new (GNC_TYPE_CURRENCY_EDIT,
352 "model", store,
353 "has-entry", true,
354 nullptr));
355 g_object_unref (store);
356
357 /* Set the column for the text */
358 gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX(gce), CURRENCY_COL_NAME);
359
360 /* Now the signals to make sure the user can't leave the
361 widget without a valid currency. */
362 gnc_cbwe_require_list_item(GTK_COMBO_BOX(gce));
363
364 /* Fill in all the data. */
365 fill_currencies (gce);
366 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(store),
367 CURRENCY_COL_NAME,
368 GTK_SORT_ASCENDING);
369
370 completion = gtk_entry_completion_new ();
371 gtk_entry_completion_set_model (completion, GTK_TREE_MODEL(store));
372 gtk_entry_completion_set_text_column (completion, CURRENCY_COL_NAME);
373 gtk_entry_completion_set_match_func (completion,
374 (GtkEntryCompletionMatchFunc)match_func,
375 GTK_TREE_MODEL(store), nullptr);
376 gtk_entry_set_completion (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (gce))),
377 completion);
378
379 return GTK_WIDGET (gce);
380}

◆ gnc_currency_edit_set_currency()

void gnc_currency_edit_set_currency ( GNCCurrencyEdit *  gce,
const gnc_commodity *  currency 
)

Set the widget to display a certain currency name.

Parameters
gceThe currency editor widget to set.
currencyThe currency to set as the displayed/selected value of the widget.

Definition at line 395 of file gnc-currency-edit.cpp.

397{
398 const gchar *printname;
399
400 g_return_if_fail(gce != nullptr);
401 g_return_if_fail(GNC_IS_CURRENCY_EDIT(gce));
402 g_return_if_fail(currency != nullptr);
403
404 printname = gnc_commodity_get_printname(currency);
405 gnc_cbwe_set_by_string(GTK_COMBO_BOX(gce), printname);
406}
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the 'print' name for the specified commodity.
void gnc_cbwe_set_by_string(GtkComboBox *cbwe, const gchar *text)
Find an entry in the GtkComboBox by its text value, and set the widget to that value.