30 #define AWAR_EPS 0.00000001
32 #if defined(DUMP_AWAR_CHANGES)
33 #define AWAR_CHANGE_DUMP(name, where, format) fprintf(stderr, "change awar '%s' " where "(" format ")\n", name, para)
35 #define AWAR_CHANGE_DUMP(name, where, format)
38 #if defined(ASSERTION_USED)
126 bool AW_awar::allowed_to_run_callbacks =
true;
129 "You cannot write to this field because it is either deleted or\n"
130 "unmapped. Try to select a different item, reselect this and retry.";
132 #define WRITE_BODY(self,format,func) \
133 if (!gb_var) return AW_MSG_UNMAPPED_AWAR; \
134 aw_assert(!deny_write); \
135 GB_transaction ta(gb_var); \
136 AWAR_CHANGE_DUMP(awar_name, #self, format); \
137 GB_ERROR error = func(gb_var, para); \
138 if (!error) update_tmp_state_during_change()
140 #define WRITE_SKELETON(self,type,format,func) \
141 GB_ERROR AW_awar::self(type para) { \
142 WRITE_BODY(self, format, func); \
145 GB_ERROR AW_awar::concatenate(re,self)(type para) { \
146 WRITE_BODY(self, format, func); \
157 #undef WRITE_SKELETON
158 #undef AWAR_CHANGE_DUMP
202 if (!
gb_var)
return strdup(
"");
228 delete refresh_list; refresh_list =
NULp;
245 target_list =
new AW_var_target((
void *)pfloat, target_list);
288 const char *var_value,
float var_float_value,
290 : callback_list(
NULp),
293 callback_time_sum(0.0),
294 callback_time_count(0),
317 in_tmp_branch = strncmp(var_name,
"tmp/", 4) == 0;
324 if (gbtype != wanted_gbtype) {
325 GB_warningf(
"Existing awar '%s' has wrong type (%i instead of %i) - recreating\n",
326 var_name,
int(gbtype),
int(wanted_gbtype));
334 case AW_STRING: default_value.s = nulldup(var_value);
break;
335 case AW_INT: default_value.l = (
long)var_value;
break;
336 case AW_FLOAT: default_value.f = var_float_value;
break;
337 case AW_POINTER: default_value.p = (GBDATA*)var_value;
break;
342 gb_def =
GB_search(default_file, var_name, wanted_gbtype);
346 #if defined(DUMP_AWAR_CHANGES)
347 fprintf(stderr,
"creating awar_string '%s' with default value '%s'\n", var_name, default_value.s);
348 #endif // DUMP_AWAR_CHANGES
353 #if defined(DUMP_AWAR_CHANGES)
354 fprintf(stderr,
"creating awar_int '%s' with default value '%li'\n", var_name, default_value.l);
355 #endif // DUMP_AWAR_CHANGES
360 #if defined(DUMP_AWAR_CHANGES)
361 fprintf(stderr,
"creating awar_float '%s' with default value '%f'\n", var_name, default_value.f);
362 #endif // DUMP_AWAR_CHANGES
367 #if defined(DUMP_AWAR_CHANGES)
368 fprintf(stderr,
"creating awar_pointer '%s' with default value '%p'\n", var_name, default_value.p);
369 #endif // DUMP_AWAR_CHANGES
374 GB_warningf(
"AWAR '%s' cannot be created because of disallowed type", var_name);
379 if (error)
GB_warningf(
"AWAR '%s': failed to set temporary on creation (Reason: %s)", var_name, error);
391 bool fix_value =
false;
395 if (
gb_var && ((pp.f.min != pp.f.max) || pp.srt)) {
399 if (lo < pp.f.min -.5) {
401 lo = (
int)(pp.f.min + 0.5);
403 if (lo>pp.f.max + .5) {
405 lo = (
int)(pp.f.max + 0.5);
436 if (strcmp(n, str) != 0) {
546 bool isSet = (pp.f.min != pp.f.max);
557 bool isSet = (pp.f.min != pp.f.max);
576 if (var[0] ==
'0' || var[0] ==
'n') {
601 if (allowed_to_run_callbacks) {
602 clock_t
start = clock();
604 AW_root_cblist::call(callback_list,
root);
606 clock_t end = clock();
609 double cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
611 if (callback_time_count>19 && (callback_time_count%2) == 0) {
612 callback_time_count = callback_time_count/2;
613 callback_time_sum = callback_time_sum/2.0;
616 callback_time_sum += cpu_time_used;
617 callback_time_count++;
626 for (pntr = target_list; pntr; pntr = pntr->
next) {
632 void AW_awar::remove_all_callbacks() {
644 remove_all_callbacks();
645 remove_all_target_vars();
652 bool make_zombie =
false;
659 if (origin_in_DB) make_zombie =
true;
662 else if (origin_in_DB) {
668 if (make_zombie)
unlink();
679 void AW_awar::remove_all_target_vars() {
680 while (target_list) {
682 target_list = tar->
next;
688 void AW_awar::update_tmp_state_during_change() {
691 if (has_managed_tmp_state()) {
696 bool has_default_value =
false;
716 allowed_to_run_callbacks =
false;
719 update_tmp_state_during_change();
721 allowed_to_run_callbacks =
true;
737 static int test_cb1_called;
738 static int test_cb2_called;
740 static void test_cb1(
AW_root *,
AW_CL cd1,
AW_CL cd2) { test_cb1_called += (cd1+cd2); }
741 static void test_cb2(
AW_root *,
AW_CL cd1,
AW_CL cd2) { test_cb2_called += (cd1+cd2); }
743 #define TEST_EXPECT_CBS_CALLED(cbl, c1,c2) \
745 test_cb1_called = test_cb2_called = 0; \
746 AW_root_cblist::call(cbl, NULp); \
747 TEST_EXPECT_EQUAL(test_cb1_called, c1); \
748 TEST_EXPECT_EQUAL(test_cb2_called, c2); \
751 void TEST_AW_root_cblist() {
754 RootCallback tcb1(test_cb1, 1, 0);
755 RootCallback tcb2(test_cb2, 0, 1);
756 RootCallback wrong_tcb2(test_cb2, 1, 0);
767 TEST_EXPECT_CBS_CALLED(cb_list, 1, 0);
771 TEST_EXPECT_CBS_CALLED(cb_list, 0, 0);
static GB_ERROR AW_MSG_UNMAPPED_AWAR
void refresh_option_menu(AW_option_menu_struct *)
GBDATA * GB_read_pointer(GBDATA *gbd)
void GB_warning(const char *message)
AW_awar * set_srt(const char *srt)
long GB_read_int(GBDATA *gbd)
GBDATA * read_pointer() const
bool GB_is_temporary(GBDATA *gbd)
GB_ERROR GB_write_string(GBDATA *gbd, const char *s)
GB_ERROR GB_add_callback(GBDATA *gbd, GB_CB_TYPE type, const DatabaseCallback &dbcb)
void update_label(Widget widget, const char *var_value)
GB_ERROR write_pointer(GBDATA *aw_pointer)
return GB_read_as_string(gb_var)
AW_awar(AW_VARIABLE_TYPE var_type, const char *var_name, const char *var_value, float var_float_value, AW_default default_file, AW_root *root)
AW_var_target(void *pntr, AW_var_target *next)
AW_VARIABLE_TYPE variable_type
static void remove(AW_root_cblist *&listhead, const RootCallback &cb)
AW_awar * set_minmax(float min, float max)
const char * GBS_global_string(const char *templat,...)
void GBK_terminatef(const char *templat,...)
char * GBS_string_eval(const char *insource, const char *icommand)
void update_text_field(Widget widget, const char *var_value)
AW_VARIABLE_TYPE get_type() const
int ARB_strNULLcmp(const char *s1, const char *s2)
void update_toggle(Widget widget, const char *var_value, AW_CL cd)
AW_awar * add_callback(const RootCallback &cb)
GB_ERROR GB_delete(GBDATA *&source)
void update_input_field(Widget widget, const char *var_value)
static HelixNrInfo * start
GB_ERROR GB_check_hkey(const char *key) __ATTR__USERESULT
#define TEST_PUBLISH(testfunction)
const char * read_char_pntr() const
GB_ERROR GB_clear_temporary(GBDATA *gbd)
GB_ERROR GB_await_error()
GB_TYPES GB_read_type(GBDATA *gbd)
void GB_warningf(const char *templat,...)
static void clear(AW_root_cblist *&listhead)
static void error(const char *msg)
GBDATA * GB_get_root(GBDATA *gbd)
#define WRITE_SKELETON(self, type, format, func)
bool unlink_from_DB(GBDATA *gb_main)
char * read_as_string() const
float GB_read_float(GBDATA *gbd)
static void AW_var_gbdata_callback(GBDATA *, AW_awar *awar)
GB_write_int const char GB_write_autoconv_string WRITE_SKELETON(write_pointer, GBDATA *,"%p", GB_write_pointer) char *AW_awa if)(!gb_var) return strdup("")
GB_ERROR reset_to_default()
void refresh_toggle_field(int toggle_field_number)
void set_temp_if_is_default(GBDATA *gb_db)
char * read_string() const
AW_awar * awar(const char *awar)
GB_ERROR GB_write_float(GBDATA *gbd, float f)
AW_awar * remove_callback(const RootCallback &cb)
GB_ERROR GB_write_int(GBDATA *gbd, long i)
GB_ERROR GB_set_temporary(GBDATA *gbd) __ATTR__USERESULT
bool member_of_DB(GBDATA *gbd, GBDATA *gb_main)
void update_scaler(Widget widget, AW_awar *awar, AW_ScalerType scalerType)
AW_awar * add_target_var(char **ppchr)
void GB_touch(GBDATA *gbd)
static void aw_cp_awar_2_widget_cb(AW_root *root, AW_widget_refresh_cb *widgetlist)
static void AW_var_gbdata_callback_delete(GBDATA *gbd, AW_awar *awar)
AW_awar * map(const char *awarn)
char * GB_read_string(GBDATA *gbd)
void GB_remove_callback(GBDATA *gbd, GB_CB_TYPE type, const DatabaseCallback &dbcb)
void update_target(AW_var_target *pntr)
void aw_message(const char *msg)
GB_ERROR write_string(const char *aw_string)
int GB_get_transaction_level(GBDATA *gbd)
Widget changer_of_variable
GB_transaction ta(gb_var)
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
GB_ERROR write_float(float aw_float)
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
GB_ERROR GB_write_pointer(GBDATA *gbd, GBDATA *pointer)
static void add(AW_root_cblist *&listhead, const RootCallback &cb)
GB_ERROR write_int(long aw_int)
struct _WidgetRec * Widget
static void AW_var_gbdata_callback_delete_intern(GBDATA *gbd, AW_awar *awar)
void tie_widget(AW_CL cd1, Widget widget, AW_widget_type type, AW_window *aww)
GB_ERROR GB_write_autoconv_string(GBDATA *gbd, const char *val)
GB_write_int const char s