GnuCash  4.11-627-g58c1a51897
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 
43 typedef QofSession * (*QofSessionCB) (void);
44 
45 
46 gchar *gnc_normalize_account_separator (const gchar* separator);
47 gboolean gnc_reverse_balance(const Account *account);
48 
49 /* Backward compatibility *******************************************
50  * Return that book's support opening balance accounts by equity type slot */
51 void gnc_set_use_equity_type_opening_balance_account (QofBook* book);
52 gboolean gnc_using_equity_type_opening_balance_account (QofBook* book);
53 
54 /* Default directory sections ***************************************/
55 #define GNC_PREFS_GROUP_OPEN_SAVE "dialogs.open-save"
56 #define GNC_PREFS_GROUP_EXPORT "dialogs.export-accounts"
57 #define GNC_PREFS_GROUP_REPORT "dialogs.report"
58 #define GNC_PREF_AUTO_DECIMAL_POINT "auto-decimal-point"
59 #define GNC_PREF_AUTO_DECIMAL_PLACES "auto-decimal-places"
60 
61 /* Default directories **********************************************/
62 
63 gchar *gnc_get_default_directory (const gchar *section);
64 void gnc_set_default_directory (const gchar *section,
65  const gchar *directory);
66 
67 /* Engine enhancements & i18n ***************************************/
68 QofBook * gnc_get_current_book (void);
69 
70 /* If there is no current session, there is no book and we must be dealing
71  * with a new book. When gnucash is started with --nofile, there is
72  * initially no session (and no book), but by the time we check, one
73  * could have been created (for example, if an empty account tree tab is
74  * opened, a session is created which creates a new, but empty, book).
75  * A session is created and a book is loaded from a backend when gnucash is
76  * started with a file, but selecting 'new file' keeps a session open. So we
77  * need to check as well for a book with no accounts (root with no children). */
78 gboolean gnc_is_new_book (void);
79 
80 void gnc_set_current_book_tax_name_type (gboolean name_changed,
81  const gchar *tax_name,
82  gboolean type_changed,
83  const gchar *tax_type);
84 const gchar * gnc_get_current_book_tax_name (void);
85 const gchar * gnc_get_current_book_tax_type (void);
89 void gnc_book_option_num_field_source_change_cb (gboolean num_action);
90 Account * gnc_get_current_root_account (void);
91 gnc_commodity_table * gnc_get_current_commodities (void);
92 
100 gchar *gnc_get_account_name_for_register(const Account *account);
101 
113 Account *gnc_account_lookup_for_register(const Account *base_account, const
114  gchar *name);
115 
125  gboolean show_leaf_accounts);
126 
127 /*
128  * This is a wrapper routine around an xaccGetBalanceInCurrency
129  * function that handles additional needs of the gui.
130  *
131  * @param fn The underlying function in Account.c to call to retrieve
132  * a specific balance from the account.
133  * @param account The account to retrieve data about.
134  * @param recurse Include all sub-accounts of this account.
135  * @param negative An indication of whether or not the returned value
136  * is negative. This can be used by the caller to
137  * easily decode whether or not to color the output.
138  * @param commodity The commodity in which the account balance should
139  * be returned. If NULL, the value will be returned in
140  * the commodity of the account. This is normally used
141  * to specify a currency, which forces the conversion
142  * of things like stock account values from share
143  * values to an amount the requested currency.
144  */
145 
146 const char * gnc_get_reconcile_str (char reconciled_flag);
147 const char * gnc_get_reconcile_valid_flags (void);
148 const char * gnc_get_reconcile_flag_order (void);
149 
150 #define WLINK 'w'
151 #define FLINK 'f'
152 
157 const char *gnc_get_doclink_valid_flags (void);
158 
163 const char *gnc_get_doclink_flag_order (void);
164 
171 const char *gnc_get_doclink_str (char link_flag);
172 
173 typedef enum
174 {
175  EQUITY_OPENING_BALANCE,
176  EQUITY_RETAINED_EARNINGS,
177  NUM_EQUITY_TYPES
178 } GNCEquityType;
179 
180 Account * gnc_find_or_create_equity_account (Account *root,
181  GNCEquityType equity_type,
182  gnc_commodity *currency);
183 gboolean gnc_account_create_opening_balance (Account *account,
184  gnc_numeric balance,
185  time64 date,
186  QofBook *book);
187 
188 /* Locale functions *************************************************/
189 
190 
194 gnc_commodity * gnc_locale_default_currency_nodefault (void);
195 
200 gnc_commodity * gnc_locale_default_currency (void);
201 
202 
209 gnc_commodity * gnc_default_currency (void);
210 
234 gnc_commodity * gnc_account_or_default_currency(const Account* account, gboolean * currency_from_account_found);
235 
242 gnc_commodity * gnc_default_report_currency (void);
243 
244 /* Amount printing and parsing **************************************/
245 
246 
247 typedef struct _GNCPrintAmountInfo
248 {
249  const gnc_commodity *commodity; /* may be NULL */
250 
251  guint8 max_decimal_places;
252  guint8 min_decimal_places;
253 
254  unsigned int use_separators : 1; /* Print thousands separators */
255  unsigned int use_symbol : 1; /* Print currency symbol */
256  unsigned int use_locale : 1; /* Use locale for some positioning */
257  unsigned int monetary : 1; /* Is a monetary quantity */
258  unsigned int force_fit : 1; /* Don't print more than max_dp places */
259  unsigned int round : 1; /* Round at max_dp instead of truncating */
261 
262 
263 GNCPrintAmountInfo gnc_default_print_info (gboolean use_symbol);
264 
265 GNCPrintAmountInfo gnc_commodity_print_info (const gnc_commodity *commodity,
266  gboolean use_symbol);
267 
268 GNCPrintAmountInfo gnc_account_print_info (const Account *account,
269  gboolean use_symbol);
270 
271 GNCPrintAmountInfo gnc_split_amount_print_info (Split *split,
272  gboolean use_symbol);
273 
274 GNCPrintAmountInfo gnc_price_print_info (const gnc_commodity *curr,
275  gboolean use_symbol);
276 
277 GNCPrintAmountInfo gnc_share_print_info_places (int decplaces);
278 GNCPrintAmountInfo gnc_default_share_print_info (void);
279 GNCPrintAmountInfo gnc_default_price_print_info (const gnc_commodity *curr);
280 
281 GNCPrintAmountInfo gnc_integral_print_info (void);
282 
283 /* WARNING: Garbage in, garbage out. You must check the validity of
284  the supplied gnc_numeric. If it's invalid, the returned string
285  could point to ANYTHING. */
286 /*
287  * The xaccPrintAmount() and xaccSPrintAmount() routines provide
288  * i18n'ed convenience routines for printing gnc_numerics.
289  * amounts. Both routines take a gnc_numeric argument and
290  * a printing information object.
291  *
292  * The xaccPrintAmount() routine returns a pointer to a statically
293  * allocated buffer, and is therefore not thread-safe.
294  *
295  * The xaccSPrintAmount() routine accepts a pointer to the buffer to be
296  * printed to. It returns the length of the printed string.
297  */
303 const char * xaccPrintAmount (gnc_numeric val, GNCPrintAmountInfo info);
310 int xaccSPrintAmount (char *buf, gnc_numeric val, GNCPrintAmountInfo info);
311 
312 const gchar *printable_value(gdouble val, gint denom);
313 gchar *number_to_words(gdouble val, gint64 denom);
314 gchar *numeric_to_words(gnc_numeric val);
315 
327 gboolean xaccParseAmount (const char * in_str, gboolean monetary,
328  gnc_numeric *result, char **endstr);
329 
339 gboolean
340 xaccParseAmountPosSign (const char * in_str, gboolean monetary, gnc_numeric *result,
341  char **endstr, gboolean skip);
342 
351 gboolean
352 xaccParseAmountExtended (const char * in_str, gboolean monetary,
353  gunichar negative_sign, gunichar decimal_point,
354  gunichar group_separator, const char *ignore_list,
355  gnc_numeric *result, char **endstr);
356 
365 const char *
367 
376 gchar *
377 gnc_wrap_text_with_bidi_ltr_isolate (const char *text);
378 
379 /* Initialization ***************************************************/
380 
381 void gnc_ui_util_init (void);
382 
383 /* Remove callback preferences **************************************/
384 
385 void gnc_ui_util_remove_registered_prefs (void);
386 
394 gchar * gnc_filter_text_for_control_chars (const gchar *incoming_text);
395 
406 void gnc_filter_text_set_cursor_position (const gchar *incoming_text,
407  const gchar *symbol,
408  gint *cursor_position);
409 
420 gchar * gnc_filter_text_for_currency_symbol (const gchar *incoming_text,
421  const gchar *symbol);
422 
433 gchar * gnc_filter_text_for_currency_commodity (const gnc_commodity *comm,
434  const gchar *incoming_text,
435  const gchar **symbol);
436 
437 #endif
438 
gchar * gnc_filter_text_for_currency_commodity(const gnc_commodity *comm, const gchar *incoming_text, const gchar **symbol)
Returns the incoming text removed of currency symbol.
Definition: gnc-ui-util.c:2310
gboolean xaccParseAmount(const char *in_str, gboolean monetary, gnc_numeric *result, char **endstr)
Parses in_str to obtain a numeric result.
Definition: gnc-ui-util.c:1757
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...
Definition: gnc-ui-util.c:742
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.
Definition: gnc-ui-util.c:1475
const char * xaccPrintAmount(gnc_numeric val, GNCPrintAmountInfo info)
Make a string representation of a gnc_numeric.
Definition: gnc-ui-util.c:1462
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 ...
gboolean xaccParseAmountPosSign(const char *in_str, gboolean monetary, gnc_numeric *result, char **endstr, gboolean skip)
Parses in_str to a gnc_numeric, with a flag to indicate whether the locale&#39;s positive sign (or in abs...
Definition: gnc-ui-util.c:1764
gnc_commodity * gnc_default_report_currency(void)
Return the default currency for use in reports, as set by the user.
Definition: gnc-ui-util.c:833
gnc_commodity * gnc_default_currency(void)
Return the default currency set by the user.
Definition: gnc-ui-util.c:800
gchar * 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 ...
Definition: gnc-ui-util.c:444
Account handling public routines.
const char * gnc_get_doclink_flag_order(void)
Get a string containing document link flag order.
Definition: gnc-ui-util.c:546
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.
Definition: gnc-ui-util.c:1803
void gnc_filter_text_set_cursor_position(const gchar *incoming_text, const gchar *symbol, gint *cursor_position)
Updates cursor_position after removal of currency symbols.
Definition: gnc-ui-util.c:2254
gchar * gnc_filter_text_for_currency_symbol(const gchar *incoming_text, const gchar *symbol)
Returns the incoming text removed of a currency symbol.
Definition: gnc-ui-util.c:2286
int xaccSPrintAmount(char *buf, gnc_numeric val, GNCPrintAmountInfo info)
Make a string representation of a gnc_numeric.
Definition: gnc-ui-util.c:1331
gchar * 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.
Definition: gnc-ui-util.c:435
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.
Definition: gnc-ui-util.c:805
gchar * 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;.
gchar * gnc_filter_text_for_control_chars(const gchar *incoming_text)
Returns the incoming text removed of control characters.
Definition: gnc-ui-util.c:2199
const char * gnc_get_doclink_str(char link_flag)
Get a string representing the document link type.
Definition: gnc-ui-util.c:522
gint64 time64
Many systems, including Microsoft Windows and BSD-derived Unixes like Darwin, are retaining the int-3...
Definition: gnc-date.h:93
const char * gnc_get_doclink_valid_flags(void)
Get a string containing documentation link valid flags.
Definition: gnc-ui-util.c:539
Account * gnc_account_lookup_for_register(const Account *base_account, const gchar *name)
Retrieve the account matching the given name starting from the descendants of base_account.
gnc_commodity * gnc_locale_default_currency(void)
Returns the default currency of the current locale.
Definition: gnc-ui-util.c:757