GnuCash  4.12-404-geb24099a91
Files | Data Structures | Macros
GncCurrencyEdit

Files

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

Data Structures

struct  GNCCurrencyEditPrivate
 The instance private data for a content plugin. More...
 
struct  GNCCurrencyEdit
 
struct  GNCCurrencyEditClass
 

Macros

#define GET_PRIVATE(o)   ((GNCCurrencyEditPrivate*)gnc_currency_edit_get_instance_private((GNCCurrencyEdit*)o))
 

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

GType gnc_currency_edit_get_type (void)
 Return the GType for the GNCCurrencyEdit currency selection widget. More...
 
#define GNC_TYPE_CURRENCY_EDIT   (gnc_currency_edit_get_type())
 
#define GNC_CURRENCY_EDIT(o)   (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_CURRENCY_EDIT, GNCCurrencyEdit))
 
#define GNC_CURRENCY_EDIT_CLASS(k)   (G_TYPE_CHECK_CLASS_CAST ((k), GNC_TYPE_CURRENCY_EDIT, GNCCurrencyEditClass))
 
#define GNC_IS_CURRENCY_EDIT(o)   (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_CURRENCY_EDIT))
 

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 474 of file gnc-currency-edit.c.

475 {
476  GtkTreeModel *model;
477  GtkWidget *entry;
478 
479  g_return_if_fail(gce != NULL);
480  g_return_if_fail(GNC_IS_CURRENCY_EDIT(gce));
481 
482  model = gtk_combo_box_get_model (GTK_COMBO_BOX(gce));
483 
484  entry = gtk_bin_get_child (GTK_BIN(gce));
485 
486  g_object_ref (model);
487 
488  g_signal_handlers_block_by_func (G_OBJECT(gce),
489  G_CALLBACK(gnc_currency_edit_active_changed), gce);
490 
491  gtk_combo_box_set_model (GTK_COMBO_BOX(gce), NULL);
492  gtk_entry_set_text (GTK_ENTRY(entry),"");
493  gtk_combo_box_set_active (GTK_COMBO_BOX(gce), -1);
494  gtk_combo_box_set_model (GTK_COMBO_BOX(gce), model);
495 
496  g_signal_handlers_block_by_func (G_OBJECT(gce),
497  G_CALLBACK(gnc_currency_edit_active_changed), gce);
498 
499  g_object_unref (model);
500 }

◆ 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 433 of file gnc-currency-edit.c.

434 {
435  gnc_commodity *commodity;
436  char *mnemonic, *name;
437  GtkTreeModel *model;
438  GtkTreeIter iter;
439 
440  g_return_val_if_fail(gce != NULL, NULL);
441  g_return_val_if_fail(GNC_IS_CURRENCY_EDIT(gce), NULL);
442 
443  if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(gce), &iter))
444  {
445  model = gtk_combo_box_get_model(GTK_COMBO_BOX(gce));
446  gtk_tree_model_get (model, &iter, 0, &mnemonic, -1);
447 
448  name = strchr(mnemonic, ' ');
449  if (name != NULL)
450  *name = '\0';
451  commodity = gnc_commodity_table_lookup (gnc_get_current_commodities (),
452  GNC_COMMODITY_NS_CURRENCY,
453  mnemonic);
454  g_free(mnemonic);
455  }
456  else
457  {
458  g_warning("Combo box returned 'inactive'. Using locale default currency.");
459  commodity = gnc_locale_default_currency();
460  }
461 
462 
463  return commodity;
464 }
gnc_commodity * gnc_locale_default_currency(void)
Returns the default currency of the current locale.
Definition: gnc-ui-util.c:757

◆ gnc_currency_edit_get_type()

GType gnc_currency_edit_get_type ( void  )

Return the GType for the GNCCurrencyEdit currency selection widget.

Returns
A GType value.

◆ 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 360 of file gnc-currency-edit.c.

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

◆ 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 411 of file gnc-currency-edit.c.

413 {
414  const gchar *printname;
415 
416  g_return_if_fail(gce != NULL);
417  g_return_if_fail(GNC_IS_CURRENCY_EDIT(gce));
418  g_return_if_fail(currency != NULL);
419 
420  printname = gnc_commodity_get_printname(currency);
421  gnc_cbwe_set_by_string(GTK_COMBO_BOX(gce), printname);
422 }
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.
Definition: gnc-gtk-utils.c:41
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the 'print' name for the specified commodity.