GnuCash  5.6-150-g038405b370+
gnc-ui-util.h
Go to the documentation of this file.
1 /********************************************************************\
2  * gnc-ui-util.h -- utility functions for the GnuCash UI *
3  * Copyright (C) 2000 Dave Peticolas <dave@krondo.com> *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License*
16  * along with this program; if not, contact: *
17  * *
18  * Free Software Foundation Voice: +1-617-542-5942 *
19  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
20  * Boston, MA 02110-1301, USA gnu@gnu.org *
21 \********************************************************************/
22 
32 #ifndef GNC_UI_UTIL_H
33 #define GNC_UI_UTIL_H
34 
35 #include <glib.h>
36 #include <locale.h>
37 
38 #include "Account.h"
39 #include "gncOwner.h"
40 #include "qof.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 
47 typedef QofSession* (*QofSessionCB) (void);
48 
49 
50 char* gnc_normalize_account_separator (const char* separator);
51 gboolean gnc_reverse_balance(const Account* account);
52 
53 /* Backward compatibility *******************************************
54  * Return that book's support opening balance accounts by equity type slot */
55 void gnc_set_use_equity_type_opening_balance_account (QofBook* book);
56 gboolean gnc_using_equity_type_opening_balance_account (QofBook* book);
57 
58 /* Default directory sections ***************************************/
59 #define GNC_PREFS_GROUP_OPEN_SAVE "dialogs.open-save"
60 #define GNC_PREFS_GROUP_EXPORT "dialogs.export-accounts"
61 #define GNC_PREFS_GROUP_REPORT "dialogs.report"
62 #define GNC_PREF_AUTO_DECIMAL_POINT "auto-decimal-point"
63 #define GNC_PREF_AUTO_DECIMAL_PLACES "auto-decimal-places"
64 
65 /* Default directories **********************************************/
66 
67 char* gnc_get_default_directory (const char* section);
68 void gnc_set_default_directory (const char* section,
69  const char* directory);
70 
71 /* Engine enhancements & i18n ***************************************/
72 QofBook* gnc_get_current_book (void);
73 
74 /* If there is no current session, there is no book and we must be dealing
75  * with a new book. When gnucash is started with --nofile, there is
76  * initially no session (and no book), but by the time we check, one
77  * could have been created (for example, if an empty account tree tab is
78  * opened, a session is created which creates a new, but empty, book).
79  * A session is created and a book is loaded from a backend when gnucash is
80  * started with a file, but selecting 'new file' keeps a session open. So we
81  * need to check as well for a book with no accounts (root with no children). */
82 gboolean gnc_is_new_book (void);
83 
84 void gnc_set_current_book_tax_name_type (gboolean name_changed,
85  const char* tax_name,
86  gboolean type_changed,
87  const char* tax_type);
88 const char* gnc_get_current_book_tax_name (void);
89 const char* gnc_get_current_book_tax_type (void);
93 void gnc_book_option_num_field_source_change_cb (gboolean num_action);
94 Account* gnc_get_current_root_account (void);
95 gnc_commodity_table* gnc_get_current_commodities (void);
96 
104 char* gnc_get_account_name_for_register(const Account* account);
105 
117 Account* gnc_account_lookup_for_register(const Account* base_account, const
118  char* name);
119 
129  gboolean show_leaf_accounts);
130 
131 /*
132  * This is a wrapper routine around an xaccGetBalanceInCurrency
133  * function that handles additional needs of the gui.
134  *
135  * @param fn The underlying function in Account.c to call to retrieve
136  * a specific balance from the account.
137  * @param account The account to retrieve data about.
138  * @param recurse Include all sub-accounts of this account.
139  * @param negative An indication of whether or not the returned value
140  * is negative. This can be used by the caller to
141  * easily decode whether or not to color the output.
142  * @param commodity The commodity in which the account balance should
143  * be returned. If NULL, the value will be returned in
144  * the commodity of the account. This is normally used
145  * to specify a currency, which forces the conversion
146  * of things like stock account values from share
147  * values to an amount the requested currency.
148  */
149 
150 const char* gnc_get_reconcile_str (char reconciled_flag);
151 const char* gnc_get_reconcile_valid_flags (void);
152 const char* gnc_get_reconcile_flag_order (void);
153 
154 #define WLINK 'w'
155 #define FLINK 'f'
156 
161 const char* gnc_get_doclink_valid_flags (void);
162 
167 const char* gnc_get_doclink_flag_order (void);
168 
175 const char* gnc_get_doclink_str (char link_flag);
176 
177 typedef enum
178 {
179  EQUITY_OPENING_BALANCE,
180  EQUITY_RETAINED_EARNINGS,
181  NUM_EQUITY_TYPES
182 } GNCEquityType;
183 
184 Account * gnc_find_or_create_equity_account (Account* root,
185  GNCEquityType equity_type,
186  gnc_commodity* currency);
187 gboolean gnc_account_create_opening_balance (Account* account,
188  gnc_numeric balance,
189  time64 date,
190  QofBook* book);
191 
192 /* Locale functions *************************************************/
193 
194 
198 gnc_commodity* gnc_locale_default_currency_nodefault (void);
199 
204 gnc_commodity* gnc_locale_default_currency (void);
205 
206 
213 gnc_commodity* gnc_default_currency (void);
214 
238 gnc_commodity* gnc_account_or_default_currency(const Account* account,
239  gboolean* currency_from_account_found);
240 
247 gnc_commodity* gnc_default_report_currency (void);
248 
249 /* Amount printing and parsing **************************************/
250 
251 
252 typedef struct _GNCPrintAmountInfo
253 {
254  const gnc_commodity *commodity; /* may be NULL */
255 
256  guint8 max_decimal_places;
257  guint8 min_decimal_places;
258 
259  unsigned int use_separators : 1; /* Print thousands separators */
260  unsigned int use_symbol : 1; /* Print currency symbol */
261  unsigned int use_locale : 1; /* Use locale for some positioning */
262  unsigned int monetary : 1; /* Is a monetary quantity */
263  unsigned int force_fit : 1; /* Don't print more than max_dp places */
264  unsigned int round : 1; /* Round at max_dp instead of truncating */
266 
267 
268 GNCPrintAmountInfo gnc_default_print_info (gboolean use_symbol);
269 
270 GNCPrintAmountInfo gnc_commodity_print_info (const gnc_commodity *commodity,
271  gboolean use_symbol);
272 
273 GNCPrintAmountInfo gnc_account_print_info (const Account *account,
274  gboolean use_symbol);
275 
276 GNCPrintAmountInfo gnc_split_amount_print_info (Split *split,
277  gboolean use_symbol);
278 
279 GNCPrintAmountInfo gnc_price_print_info (const gnc_commodity *curr,
280  gboolean use_symbol);
281 
282 GNCPrintAmountInfo gnc_share_print_info_places (int decplaces);
283 GNCPrintAmountInfo gnc_default_share_print_info (void);
284 GNCPrintAmountInfo gnc_default_price_print_info (const gnc_commodity *curr);
285 
286 GNCPrintAmountInfo gnc_integral_print_info (void);
287 
288 /* WARNING: Garbage in, garbage out. You must check the validity of
289  the supplied gnc_numeric. If it's invalid, the returned string
290  could point to ANYTHING. */
291 /*
292  * The xaccPrintAmount() and xaccSPrintAmount() routines provide
293  * i18n'ed convenience routines for printing gnc_numerics.
294  * amounts. Both routines take a gnc_numeric argument and
295  * a printing information object.
296  *
297  * The xaccPrintAmount() routine returns a pointer to a statically
298  * allocated buffer, and is therefore not thread-safe.
299  *
300  * The xaccSPrintAmount() routine accepts a pointer to the buffer to be
301  * printed to. It returns the length of the printed string.
302  */
308 const char* xaccPrintAmount (gnc_numeric val, GNCPrintAmountInfo info);
315 int xaccSPrintAmount (char* buf, gnc_numeric val, GNCPrintAmountInfo info);
316 
317 const char* printable_value(gdouble val, gint denom);
318 char* number_to_words(gdouble val, gint64 denom);
319 char* numeric_to_words(gnc_numeric val);
320 
332 gboolean xaccParseAmount (const char* in_str, gboolean monetary,
333  gnc_numeric* result, char** endstr);
334 
343 gboolean
344 xaccParseAmountExtended (const char* in_str, gboolean monetary,
345  gunichar negative_sign, gunichar decimal_point,
346  gunichar group_separator, const char* ignore_list,
347  gnc_numeric* result, char** endstr);
348 
363 gboolean
364 xaccParseAmountImport (const char* in_str, gboolean monetary,
365  gnc_numeric* result,
366  char** endstr, gboolean skip);
367 
374 gboolean
375 xaccParseAmountExtImport (const char* in_str, gboolean monetary,
376  gunichar negative_sign, gunichar decimal_point,
377  gunichar group_separator, const char* ignore_list,
378  gnc_numeric* result, char** endstr);
379 
388 const char*
390  GNCPrintAmountInfo info);
391 
400 char*
401 gnc_wrap_text_with_bidi_ltr_isolate (const char* text);
402 
403 /* Initialization ***************************************************/
404 
405 void gnc_ui_util_init (void);
406 
407 /* Remove callback preferences **************************************/
408 
409 void gnc_ui_util_remove_registered_prefs (void);
410 
418 char* gnc_filter_text_for_control_chars (const char* incoming_text);
419 
430 void gnc_filter_text_set_cursor_position (const char* incoming_text,
431  const char* symbol,
432  int* zcursor_position);
433 
444 char* gnc_filter_text_for_currency_symbol (const char* incoming_text,
445  const char* symbol);
446 
457 char* gnc_filter_text_for_currency_commodity (const gnc_commodity *comm,
458  const char* incoming_text,
459  const char** symbol);
460 
468 gchar* gnc_list_formatter (GList* strings);
469 
470 #ifdef __cplusplus
471 }
472 #endif
473 
474 #endif
475 
gboolean xaccParseAmount(const char *in_str, gboolean monetary, gnc_numeric *result, char **endstr)
Parses in_str to obtain a numeric result.
gboolean xaccParseAmountImport(const char *in_str, gboolean monetary, gnc_numeric *result, char **endstr, gboolean skip)
Similar to xaccParseAmount, but with two differences.
gnc_commodity * gnc_locale_default_currency_nodefault(void)
Returns the default currency of the current locale, or NULL if no sensible currency could be identifi...
Business Interface: Object OWNERs.
const char * gnc_print_amount_with_bidi_ltr_isolate(gnc_numeric val, GNCPrintAmountInfo info)
Make a string representation of a gnc_numeric.
STRUCTS.
char * gnc_wrap_text_with_bidi_ltr_isolate(const char *text)
This function helps with GTK&#39;s use of &#39;Unicode Bidirectional Text Algorithm&#39;.
const char * xaccPrintAmount(gnc_numeric val, GNCPrintAmountInfo info)
Make a string representation of a gnc_numeric.
void gnc_book_option_num_field_source_change_cb(gboolean num_action)
Calls gnc_book_option_num_field_source_change to initiate registered callbacks when num_field_source ...
char * gnc_filter_text_for_currency_commodity(const gnc_commodity *comm, const char *incoming_text, const char **symbol)
Returns the incoming text removed of currency symbol.
gnc_commodity * gnc_default_report_currency(void)
Return the default currency for use in reports, as set by the user.
gnc_commodity * gnc_default_currency(void)
Return the default currency set by the user.
gboolean xaccParseAmountExtImport(const char *in_str, gboolean monetary, gunichar negative_sign, gunichar decimal_point, gunichar group_separator, const char *ignore_list, gnc_numeric *result, char **endstr)
Similar to xaccParseAmountExtended, but will not automatically set a decimal point, regardless of what the user has set for this option.
char * gnc_get_account_name_for_register(const Account *account)
Get either the full name of the account or the simple name, depending on the configuration parameter ...
Account handling public routines.
char * gnc_get_account_name_for_split_register(const Account *account, gboolean show_leaf_accounts)
Get either the full name of the account or the simple name, depending on the show_leaf_accounts.
const char * gnc_get_doclink_flag_order(void)
Get a string containing document link flag order.
gboolean xaccParseAmountExtended(const char *in_str, gboolean monetary, gunichar negative_sign, gunichar decimal_point, gunichar group_separator, const char *ignore_list, gnc_numeric *result, char **endstr)
Converts a string to a gnc_numeric.
void gnc_filter_text_set_cursor_position(const char *incoming_text, const char *symbol, int *zcursor_position)
Updates cursor_position after removal of currency symbols.
gchar * gnc_list_formatter(GList *strings)
This function takes a GList of char*, and uses locale-sensitive list formatter.
int xaccSPrintAmount(char *buf, gnc_numeric val, GNCPrintAmountInfo info)
Make a string representation of a gnc_numeric.
char * gnc_filter_text_for_control_chars(const char *incoming_text)
Returns the incoming text removed of control characters.
Account * gnc_account_lookup_for_register(const Account *base_account, const char *name)
Retrieve the account matching the given name starting from the descendants of base_account.
gnc_commodity * gnc_account_or_default_currency(const Account *account, gboolean *currency_from_account_found)
Returns a gnc_commodity that is a currency, suitable for being a Transaction&#39;s currency.
char * gnc_filter_text_for_currency_symbol(const char *incoming_text, const char *symbol)
Returns the incoming text removed of a currency symbol.
const char * gnc_get_doclink_str(char link_flag)
Get a string representing the document link type.
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition: gnc-date.h:87
const char * gnc_get_doclink_valid_flags(void)
Get a string containing documentation link valid flags.
gnc_commodity * gnc_locale_default_currency(void)
Returns the default currency of the current locale.