1 /********************************************************************\ 2 * gnc-amount-edit.h -- amount editor widget * 3 * * 4 * Copyright (C) 2000 Dave Peticolas <dave@krondo.com> * 5 * * 6 * This program is free software; you can redistribute it and/or * 7 * modify it under the terms of the GNU General Public License as * 8 * published by the Free Software Foundation; either version 2 of * 9 * the License, or (at your option) any later version. * 10 * * 11 * This program is distributed in the hope that it will be useful, * 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 14 * GNU General Public License for more details. * 15 * * 16 * You should have received a copy of the GNU General Public License* 17 * along with this program; if not, contact: * 18 * * 19 * Free Software Foundation Voice: +1-617-542-5942 * 20 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 * 21 * Boston, MA 02110-1301, USA gnu@gnu.org * 22 \********************************************************************/ 23 /* 24 @NOTATION@ 25 */ 26 27 #ifndef GNC_AMOUNT_EDIT_H 28 #define GNC_AMOUNT_EDIT_H 29 30 #include "qof.h" 31 #include "gnc-ui-util.h" 32 33 #include <gtk/gtk.h> 34 35 #define GNC_TYPE_AMOUNT_EDIT (gnc_amount_edit_get_type ()) 36 #define GNC_AMOUNT_EDIT(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, GNC_TYPE_AMOUNT_EDIT, GNCAmountEdit) 37 #define GNC_AMOUNT_EDIT_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, GNC_TYPE_AMOUNT_EDIT, GNCAmountEditClass) 38 #define GNC_IS_AMOUNT_EDIT(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, GNC_TYPE_AMOUNT_EDIT) 39 40 typedef struct 41 { 42 GtkBox box; 43 GtkEntry *entry; 44 GtkWidget *image; 45 46 gboolean disposed; 47 48 gboolean need_to_parse; 49 50 GNCPrintAmountInfo print_info; 51 52 gboolean block_changed; 53 54 gnc_numeric amount; 55 56 int fraction; 57 58 gboolean evaluate_on_enter; 59 gboolean validate_on_change; 60 61 gboolean show_warning_symbol; 62 63 } GNCAmountEdit; 64 65 typedef struct 66 { 67 GtkBoxClass parent_class; 68 69 /* Signals for notification/filtering of changes */ 70 void (*activate) (GNCAmountEdit *gae); 71 void (*changed) (GNCAmountEdit *gae); 72 void (*amount_changed) (GNCAmountEdit *gae); 73 } GNCAmountEditClass; 74 75 /** 76 * gnc_amount_edit_get_type: 77 * 78 * Returns the GType for the GNCAmountEdit widget 79 */ 80 GType gnc_amount_edit_get_type (void) G_GNUC_CONST; 81 82 /** 83 * gnc_amount_edit_new: 84 * 85 * Creates a new GNCAmountEdit widget which can be used to provide 86 * an easy to use way for entering amounts, allowing the user to 87 * enter and evaluate expressions. 88 * 89 * Returns a GNCAmountEdit widget. 90 */ 91 GtkWidget *gnc_amount_edit_new (void); 92 93 /** 94 * gnc_amount_edit_gtk_entry: 95 * @gae: The GNCAmountEdit widget 96 * 97 * Returns the gtk entry of the widget.. 98 */ 99 GtkWidget *gnc_amount_edit_gtk_entry (GNCAmountEdit *gae); 100 101 /** 102 * gnc_amount_edit_set_amount: 103 * @gae: The GNCAmountEdit widget 104 * @amount: The amount to set as gnc_numeric 105 * 106 * Returns nothing. 107 */ 108 void gnc_amount_edit_set_amount (GNCAmountEdit *gae, 109 gnc_numeric amount); 110 111 /** 112 * gnc_amount_edit_set_damount: 113 * @gae: The GNCAmountEdit widget 114 * @amount: The amount to set as a double 115 * 116 * Returns nothing. 117 */ 118 void gnc_amount_edit_set_damount (GNCAmountEdit *gae, 119 double amount); 120 121 /** 122 * gnc_amount_edit_get_amount: 123 * @gae: The GNCAmountEdit widget 124 * 125 * Returns the amount entered in the GNCAmountEdit widget as 126 * a gnc_numeric, parsing the expression if necessary. 127 * The result of parsing replaces the expression. 128 */ 129 gnc_numeric gnc_amount_edit_get_amount (GNCAmountEdit *gae); 130 131 /** 132 * gnc_amount_edit_get_damount: 133 * @gae: The GNCAmountEdit widget 134 * 135 * Returns the amount entered in the GNCAmountEdit widget as 136 * a double, parsing the expression if necessary. 137 * The result of parsing replaces the expression. 138 */ 139 double gnc_amount_edit_get_damount (GNCAmountEdit *gae); 140 141 /** 142 * gnc_amount_edit_expr_is_valid 143 * @gae: The GNCAmountEdit widget 144 * @amount: parameter to hold the value of the parsed expression 145 * @empty_ok: if true, an empty field is skipped, otherwise an empty field 146 * parses as 0 147 * @error: if error location information is available it will be stored 148 * in this variable. Set it to NULL if you don't want the error. 149 * 150 * If needed, parse the expression in the amount entry. If there's no 151 * parsing error, it returns the amount, otherwise it returns the 152 * position in the expression where the error occurred. 153 * 154 * Return * 0 if the parsing was successful (note that if !empty_ok, 155 * an empty field will parse to 0) 156 * * -1 if the field is empty and that's ok (empty_ok) 157 * * 1 parsing failed 158 */ 159 gint gnc_amount_edit_expr_is_valid (GNCAmountEdit *gae, 160 gnc_numeric *amount, 161 gboolean empty_ok, 162 GError **error); 163 164 /** 165 * gnc_amount_edit_evaluate 166 * @gae: The GNCAmountEdit widget 167 * @error: if error location information is available it will be stored 168 * in this variable. Set it to NULL if you don't want the error. 169 * 170 * If needed, parse the expression in the amount entry 171 * and replace the expression with the result of evaluation. 172 * If there is a parsing error, don't change the expression entry, 173 * but do put the cursor at the point of the error. 174 * 175 * Return TRUE if parsing was successful or there was no need to parse. 176 */ 177 gboolean gnc_amount_edit_evaluate (GNCAmountEdit *gae, GError **error); 178 179 /** 180 * gnc_amount_edit_set_print_flags: 181 * @gae: The GNCAmountEdit widget 182 * @print_flags: The print flags to set 183 * 184 * Returns nothing. 185 */ 186 void gnc_amount_edit_set_print_info (GNCAmountEdit *gae, 187 GNCPrintAmountInfo print_info); 188 189 /** 190 * gnc_amount_edit_set_fraction: 191 * @gae: The GNCAmountEdit widget 192 * @fraction: The fraction to set 193 * 194 * Returns nothing. 195 */ 196 void gnc_amount_edit_set_fraction (GNCAmountEdit *gae, int fraction); 197 198 /** 199 * gnc_amount_edit_set_evaluate_on_enter: 200 * @gae: The GNCAmountEdit widget 201 * @evaluate_on_enter: The flag value to set 202 * 203 * Returns nothing. 204 */ 205 void gnc_amount_edit_set_evaluate_on_enter (GNCAmountEdit *gae, 206 gboolean evaluate_on_enter); 207 208 /** 209 * gnc_amount_edit_set_validate_on_change: 210 * @gae: The GNCAmountEdit widget 211 * @validate_on_change: The flag value to set 212 * 213 * Returns nothing. 214 */ 215 void gnc_amount_edit_set_validate_on_change (GNCAmountEdit *gae, 216 gboolean validate_on_change); 217 218 /** 219 * gnc_amount_edit_select_region: 220 * @gae: The GNCAmountEdit widget 221 * @start_pos: start of region 222 * @end_pos: end of region 223 * 224 * Returns nothing. 225 */ 226 void gnc_amount_edit_select_region (GNCAmountEdit *gae, 227 gint start_pos, 228 gint end_pos); 229 230 /** 231 * gnc_amount_edit_show_warning_symbol: 232 * @gae: The GNCAmountEdit widget 233 * @show: default is TRUE to show warning symbol, FALSE to not. 234 * 235 * Returns nothing. 236 */ 237 void gnc_amount_edit_show_warning_symbol (GNCAmountEdit *gae, gboolean show); 238 239 /** 240 * gnc_amount_edit_make_mnemonic_target: 241 * @gae: The GNCAmountEdit widget 242 * @label: The label whose access key should set focus to this widget. 243 * 244 * Returns nothing. 245 */ 246 void gnc_amount_edit_make_mnemonic_target (GNCAmountEdit *gae, GtkWidget *label); 247 248 #endif 249