00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "config.h"
00037
00038 #include <stdlib.h>
00039 #include <string.h>
00040
00041 #include "basiccell.h"
00042 #include "gnc-engine.h"
00043
00044
00045 static QofLogModule log_module = GNC_MOD_REGISTER;
00046
00047 gboolean
00048 gnc_cell_name_equal (const char * cell_name_1,
00049 const char * cell_name_2)
00050 {
00051 return (safe_strcmp (cell_name_1, cell_name_2) == 0);
00052 }
00053
00054 BasicCell *
00055 gnc_basic_cell_new (void)
00056 {
00057 BasicCell * cell;
00058
00059 cell = g_new0 (BasicCell, 1);
00060
00061 gnc_basic_cell_init (cell);
00062
00063 return cell;
00064 }
00065
00066 static void
00067 gnc_basic_cell_clear (BasicCell *cell)
00068 {
00069 g_free (cell->cell_name);
00070 cell->cell_name = NULL;
00071 g_free (cell->cell_type_name);
00072 cell->cell_type_name = NULL;
00073 cell->changed = FALSE;
00074 cell->conditionally_changed = FALSE;
00075
00076 cell->value = NULL;
00077 cell->value_chars = 0;
00078
00079 cell->set_value = NULL;
00080 cell->enter_cell = NULL;
00081 cell->modify_verify = NULL;
00082 cell->direct_update = NULL;
00083 cell->leave_cell = NULL;
00084 cell->gui_realize = NULL;
00085 cell->gui_move = NULL;
00086 cell->gui_destroy = NULL;
00087
00088 cell->is_popup = FALSE;
00089
00090 cell->gui_private = NULL;
00091
00092 g_free (cell->sample_text);
00093 cell->sample_text = NULL;
00094 }
00095
00096 void
00097 gnc_basic_cell_init (BasicCell *cell)
00098 {
00099 gnc_basic_cell_clear (cell);
00100
00101 cell->value = g_strdup ("");
00102 }
00103
00104 void
00105 gnc_basic_cell_destroy (BasicCell *cell)
00106 {
00107 ENTER(" ");
00108 if (cell->destroy)
00109 cell->destroy (cell);
00110
00111
00112 if (cell->gui_destroy)
00113 (*(cell->gui_destroy)) (cell);
00114
00115
00116 g_free (cell->value);
00117 cell->value = NULL;
00118
00119
00120 gnc_basic_cell_clear (cell);
00121
00122
00123 g_free (cell);
00124 LEAVE(" ");
00125 }
00126
00127 void
00128 gnc_basic_cell_set_name (BasicCell *cell, const char *name)
00129 {
00130 if (!cell) return;
00131 if (cell->cell_name == name) return;
00132
00133 g_free (cell->cell_name);
00134 cell->cell_name = g_strdup (name);
00135 }
00136
00137 gboolean
00138 gnc_basic_cell_has_name (BasicCell *cell, const char *name)
00139 {
00140 if (!cell) return FALSE;
00141 if (!name) return FALSE;
00142 if (!cell->cell_name) return FALSE;
00143
00144 return (strcmp (name, cell->cell_name) == 0);
00145 }
00146
00147
00148 void
00149 gnc_basic_cell_set_type_name (BasicCell *cell, const gchar *type_name)
00150 {
00151 if (!cell) return;
00152 if (cell->cell_type_name == type_name) return;
00153
00154 g_free (cell->cell_type_name);
00155 cell->cell_type_name = g_strdup(type_name);
00156 }
00157
00158 gboolean
00159 gnc_basic_cell_has_type_name (BasicCell *cell, const gchar *type_name)
00160 {
00161 if (!cell) return FALSE;
00162 if (!type_name) return FALSE;
00163 if (!cell->cell_type_name) return FALSE;
00164
00165 return (g_strcmp0 (type_name, cell->cell_type_name));
00166 }
00167
00168 void
00169 gnc_basic_cell_set_sample_text (BasicCell *cell,
00170 const char *sample_text)
00171 {
00172 if (!cell) return;
00173 if (cell->sample_text == sample_text) return;
00174
00175 g_free (cell->sample_text);
00176 cell->sample_text = g_strdup (sample_text);
00177 }
00178
00179 void
00180 gnc_basic_cell_set_alignment (BasicCell *cell,
00181 CellAlignment alignment)
00182 {
00183 if (!cell) return;
00184 cell->alignment = alignment;
00185 }
00186
00187 void
00188 gnc_basic_cell_set_expandable (BasicCell *cell, gboolean expandable)
00189 {
00190 if (!cell) return;
00191 cell->expandable = expandable;
00192 }
00193
00194 void
00195 gnc_basic_cell_set_span (BasicCell *cell, gboolean span)
00196 {
00197 if (!cell) return;
00198 cell->span = span;
00199 }
00200
00201 const char *
00202 gnc_basic_cell_get_value (BasicCell *cell)
00203 {
00204 g_return_val_if_fail (cell != NULL, NULL);
00205
00206 return cell->value;
00207 }
00208
00209 void
00210 gnc_basic_cell_set_value (BasicCell *cell, const char *val)
00211 {
00212 CellSetValueFunc cb;
00213
00214 cb = cell->set_value;
00215 if (cb)
00216 {
00217
00218
00219 cell->set_value = NULL;
00220 cb (cell, val);
00221 cell->set_value = cb;
00222 }
00223 else
00224 gnc_basic_cell_set_value_internal (cell, val);
00225 }
00226
00227 gboolean
00228 gnc_basic_cell_get_changed (BasicCell *cell)
00229 {
00230 if (!cell) return FALSE;
00231
00232 return cell->changed;
00233 }
00234
00235 gboolean
00236 gnc_basic_cell_get_conditionally_changed (BasicCell *cell)
00237 {
00238 if (!cell) return FALSE;
00239
00240 return cell->conditionally_changed;
00241 }
00242
00243 void
00244 gnc_basic_cell_set_changed (BasicCell *cell, gboolean changed)
00245 {
00246 if (!cell) return;
00247
00248 cell->changed = changed;
00249 }
00250
00251 void
00252 gnc_basic_cell_set_conditionally_changed (BasicCell *cell, gboolean changed)
00253 {
00254 if (!cell) return;
00255
00256 cell->conditionally_changed = changed;
00257 }
00258
00259 void
00260 gnc_basic_cell_set_value_internal (BasicCell *cell, const char *value)
00261 {
00262 if (value == NULL)
00263 value = "";
00264
00265
00266
00267
00268
00269
00270 if (cell->value == value)
00271 return;
00272
00273 g_free (cell->value);
00274 cell->value = g_strdup (value);
00275 cell->value_chars = g_utf8_strlen(value, -1);
00276 }