GnuCash  5.6-150-g038405b370+
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. More...
 

Get/Set Functions

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

Basic Object Implementation

#define GNC_TYPE_CURRENCY_EDIT   (gnc_currency_edit_get_type())
 

Detailed Description

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 465 of file gnc-currency-edit.cpp.

466 {
467  GtkTreeModel *model;
468  GtkWidget *entry;
469 
470  g_return_if_fail(gce != nullptr);
471  g_return_if_fail(GNC_IS_CURRENCY_EDIT(gce));
472 
473  model = gtk_combo_box_get_model (GTK_COMBO_BOX(gce));
474 
475  entry = gtk_bin_get_child (GTK_BIN(gce));
476 
477  g_object_ref (model);
478 
479  g_signal_handlers_block_by_func (G_OBJECT(gce),
480  (gpointer)gnc_currency_edit_active_changed, gce);
481 
482  gtk_combo_box_set_model (GTK_COMBO_BOX(gce), nullptr);
483  gtk_entry_set_text (GTK_ENTRY(entry),"");
484  gtk_combo_box_set_active (GTK_COMBO_BOX(gce), -1);
485  gtk_combo_box_set_model (GTK_COMBO_BOX(gce), model);
486 
487  g_signal_handlers_unblock_by_func (G_OBJECT(gce),
488  (gpointer)gnc_currency_edit_active_changed, gce);
489 
490  g_object_unref (model);
491 }

◆ 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 424 of file gnc-currency-edit.cpp.

425 {
426  gnc_commodity *commodity;
427  char *mnemonic, *name;
428  GtkTreeModel *model;
429  GtkTreeIter iter;
430 
431  g_return_val_if_fail(gce != nullptr, nullptr);
432  g_return_val_if_fail(GNC_IS_CURRENCY_EDIT(gce), nullptr);
433 
434  if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(gce), &iter))
435  {
436  model = gtk_combo_box_get_model(GTK_COMBO_BOX(gce));
437  gtk_tree_model_get (model, &iter, 0, &mnemonic, -1);
438 
439  name = strchr(mnemonic, ' ');
440  if (name != nullptr)
441  *name = '\0';
442  commodity = gnc_commodity_table_lookup (gnc_get_current_commodities (),
443  GNC_COMMODITY_NS_CURRENCY,
444  mnemonic);
445  g_free(mnemonic);
446  }
447  else
448  {
449  g_warning("Combo box returned 'inactive'. Using locale default currency.");
450  commodity = gnc_locale_default_currency();
451  }
452 
453 
454  return commodity;
455 }
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 351 of file gnc-currency-edit.cpp.

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

◆ 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 402 of file gnc-currency-edit.cpp.

404 {
405  const gchar *printname;
406 
407  g_return_if_fail(gce != nullptr);
408  g_return_if_fail(GNC_IS_CURRENCY_EDIT(gce));
409  g_return_if_fail(currency != nullptr);
410 
411  printname = gnc_commodity_get_printname(currency);
412  gnc_cbwe_set_by_string(GTK_COMBO_BOX(gce), printname);
413 }
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.
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the 'print' name for the specified commodity.